Skip to content

MMU cache statistics no longer displayed #113

@yy214123

Description

@yy214123

Description

Starting from commit b50f948,
cache performance statistics were introduced and could be enabled by adding the following flag in Makefile:

+   CFLAGS += -DMMU_CACHE_STATS

Running $ make check would then output cache hit/miss statistics similar to:

=== MMU Cache Statistics ===

Hart 0:
  Fetch:    447698001 hits,     18085039 misses (96.12% hit rate)
  Load:      66831913 hits,     36133463 misses (2-way) (64.91% hit rate)
  Store:     61496139 hits,     11831421 misses (83.86% hit rate)

However, after rebasing my branch on recent upstream commits, the cache statistics feature no longer works as expected.
I found that from commit e9fa09a onward, compilation fails due to missing signal declarations:

main.c:1273:5: error: implicit declaration of function ‘signal’; did you mean ‘strsignal’? [-Wimplicit-function-declaration]
 1273 |     signal(SIGINT, signal_handler_stats);
      |     ^~~~~~
      |     strsignal
main.c:1273:12: error: ‘SIGINT’ undeclared (first use in this function)
 1273 |     signal(SIGINT, signal_handler_stats);
      |            ^~~~~~
main.c:1273:12: note: each undeclared identifier is reported only once for each function it appears in
main.c:1274:12: error: ‘SIGTERM’ undeclared (first use in this function)
 1274 |     signal(SIGTERM, signal_handler_stats);
      |            ^~~~~~~
make: *** [Makefile:208: main.o] Error 1

This was resolved by explicitly #including <signal.h> in main.c (until commit e2a5b74),

From commit 137d4d0 (“Refine coroutine for hart scheduling”) onward, even with the signal declarations added, the MMU cache statistics no longer produces any runtime output.

Observations

By comparing e2a5b74 and 137d4d0, I noticed that the following timing and signal-handling logic was removed:

#ifdef MMU_CACHE_STATS
    /* Check if signal received (SIGINT/SIGTERM) */
    if (signal_received) {
        print_mmu_cache_stats(&emu->vm);
        return 0;
    }
    /* Exit after running for 15 seconds to collect statistics */
    gettimeofday(&current_time, NULL);
    long elapsed_sec = current_time.tv_sec - start_time.tv_sec;
    long elapsed_usec = current_time.tv_usec - start_time.tv_usec;
    if (elapsed_usec < 0) {
        elapsed_sec--;
        elapsed_usec += 1000000;
    }
    long elapsed = elapsed_sec + (elapsed_usec > 0 ? 1 : 0);
    if (elapsed >= 15) {
        fprintf(stderr,
                "\n[MMU_CACHE_STATS] Reached 15 second time limit, "
                "exiting...\n");
        return 0;
    }
#endif

I’m not yet sure how to re-enable the MMU cache statistics after the coroutine refinement.
Are there any design introduced in that refactor that might interfere with it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions