Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions source/SpinalHDL/Libraries/Misc/Plru.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,49 @@ Plru

Introduction
------------
- Pseudo least recently used combinatorial logic
- io.context.state need to be handled externally.
- When you want to specify a access to a entry, you can use the io.update interface to get the new state value.
- plru.io.evict.id tells you the id of the next block to be evicted
- plru.io.update.id lets you update what you recently used

The `Pseudo Least Recently Used <https://en.wikipedia.org/wiki/Pseudo-LRU>`_
algorithm can be used for example in cache to select efficiently a line
for eviction.

PLRU Code
It is used for example `in the VexiiRiscV core <https://github.com/SpinalHDL/VexiiRiscv/blob/3cff1cc2411ca97e6ee9ef64414ef274d30371e1/src/main/scala/vexiiriscv/execute/lsu/LsuL1Plugin.scala#L830>`_
or in `spinal.lib.bus.tilelink.coherent.Cache <https://github.com/SpinalHDL/SpinalHDL/blob/78f29dc66110fc099a777992b6daa2f803ab445e/lib/src/main/scala/spinal/lib/bus/tilelink/coherent/Cache.scala#L1026>`_.

- ``io.context.state`` need to be handled externally.
- When you want to specify a access to a entry, you can use the ``io.update``
interface to get the new state value.
- ``plru.io.evict.id`` tells you the id of the next block to be evicted
- ``plru.io.update.id`` lets you update what you recently used


PLRU Code:

.. code-block:: scala

val io = new Bundle{
val context = new Bundle{
//user -> plru, specify the current state
val io = new Bundle {
val context = new Bundle {
// user -> plru, specify the current state
val state = Plru.State(entries)
//user -> plru, allow to specify prefered entries to remove. each bit set mean : "i would prefer that way to not to be selected by PLRU"
// user -> plru, allow to specify preferred entries to remove. Each bit
// set mean : "i would prefer that way to not to be selected by PLRU"
val valids = withEntriesValid generate Bits(entries bits)
}
val evict = new Bundle{
//PLRU -> user, Tells you the least recently used entry for the given context provided above
val evict = new Bundle {
// PLRU -> user, Tells you the least recently used entry for the
// given context provided above
val id = UInt(log2Up(entries) bits)
}
val update = new Bundle{
// user -> PLRU specify which entry the user want to mark as most recently used
val update = new Bundle {
// user -> PLRU specify which entry the user want to mark as
// most recently used
val id = UInt(log2Up(entries) bits)
// PLRU -> user specfy what should then be the new value of the PLRU status
// PLRU -> user specfy what should then be the new value of the PLRU status
val state = Plru.State(entries)
}
}


Example usage in a cache
Example usage in a cache:

.. code-block:: scala

Expand All @@ -51,13 +62,13 @@ Example usage in a cache
}


Get the ID of the way to evict from
Get the ID of the way to evict from:

.. code-block:: scala

val replacedWay = plru.io.evict.id

Update recently used way
Update recently used way:

.. code-block:: scala

Expand Down
1 change: 1 addition & 0 deletions source/SpinalHDL/Libraries/Misc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Misc

*/*
service_plugin
Plru
Loading