Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • D dynamorio
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,467
    • Issues 1,467
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 44
    • Merge requests 44
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • DynamoRIO
  • dynamorio
  • Issues
  • #5456
Closed
Open
Issue created Apr 11, 2022 by Nahome Bete@bete0Contributor

Calling `cache_fifo::replace_which_way()` directly results in a change in FIFO cache state

While working on a unit test for clients/drcachesim/simulator/cache_fifo.cpp (https://github.com/DynamoRIO/dynamorio/pull/5454), I discovered that calling cache_fifo::replace_which_way() right after accessing a cache line (by calling request()) would update the cache state.

For the cache replacement unit tests, we validate the expected way is replaced after an access by first sending a request() and then checking the way to be replaced on the next access matches the expected way as shown below (from https://github.com/DynamoRIO/dynamorio/pull/5454):

 void
 access_and_check_fifo(const addr_t addr,
                          const int expected_replacement_way_after_access)
 {
        memref_t ref;
        ref.data.type = TRACE_TYPE_READ;
        ref.data.size = 1;
        ref.data.addr = addr;
        request(ref);
        assert(replace_which_way(get_block_index(addr)) ==
                                 expected_replacement_way_after_access);
}

However calling replace_which_way() changes the state of the FIFO cache by updating the way to be replaced which results in the wrong way to be replaced on the next access.

This is not necessarily a bug in the FIFO cache replacement implementation but makes testing the implementation harder and potentially could result in unexpected behavior if cache_fifo::replace_which_way() is called directly somewhere else.

Steps to reproduce the behavior:

  1. Checkout PR https://github.com/DynamoRIO/dynamorio/pull/5454, build and run drcachesim unit test and observe the test fails
  2. Update the test cases from https://github.com/DynamoRIO/dynamorio/pull/5454/files#diff-b7acbebc334f2800e156dcb14d7ad91ea8b243fee66b9cf3011430d2605081b9R165-R168 as follows and observe the test passes
  cache_fifo_test.access_and_check_fifo(ADDRESS_A, 1); // A x X X
  cache_fifo_test.access_and_check_fifo(ADDRESS_B, 3); // A B x X
  cache_fifo_test.access_and_check_fifo(ADDRESS_C, 1); // A B C x
  cache_fifo_test.access_and_check_fifo(ADDRESS_D, 3); // a B C D
Assignee
Assign to
Time tracking