Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong cache sizes ? #192

Open
Sparkenstein opened this issue Oct 4, 2024 · 2 comments
Open

Wrong cache sizes ? #192

Sparkenstein opened this issue Oct 4, 2024 · 2 comments
Labels

Comments

@Sparkenstein
Copy link

Sorry if I don't understand this correctly, as I am not well versed with rust, but from example I am getting cache sizes as:

L1 Instruction-Cache: (32 KiB, 8-way associativity, direct-mapped)
L1 Data-Cache: (32 KiB, 8-way associativity, direct-mapped)
L2 Unified-Cache: (1024 KiB, 8-way associativity, direct-mapped)
L3 Unified-Cache: (96 MiB, 16-way associativity, direct-mapped)

So far so good, but I am using AMD Ryzen 7800X3D 8-Core Processor. Official spec and windows system monitor both report L2 cache size as 512KB.

The example says the calculation of cache is :

let size = cache.associativity()
                    * cache.physical_line_partitions()
                    * cache.coherency_line_size()
                    * cache.sets();

But its associativity is 8 way, so do I have to multiply size with associativity again? (that gives 8MB which is correct cache size). that also works with L1 because L1 data + Instruction is given as 32 so (32x8)x2 gives 512.

If that's the case, then why L3 is reported correctly? Is this a bug?
Following are the cache objects for L2 and L3.

CacheParameter {
    cache_type: Unified,
    level: 3,
    is_self_initializing: true,
    is_fully_associative: false,
    max_cores_for_cache: 16,
    max_cores_for_package: 1,
    coherency_line_size: 64,
    physical_line_partitions: 1,
    associativity: 16,
    sets: 98304,
    is_write_back_invalidate: true,
    is_inclusive: false,
    has_complex_indexing: false,
}
CacheParameter {
    cache_type: Unified,
    level: 2,
    is_self_initializing: true,
    is_fully_associative: false,
    max_cores_for_cache: 2,
    max_cores_for_package: 1,
    coherency_line_size: 64,
    physical_line_partitions: 1,
    associativity: 8,
    sets: 2048,
    is_write_back_invalidate: false,
    is_inclusive: true,
    has_complex_indexing: false,
}
@gz
Copy link
Owner

gz commented Oct 8, 2024

Note that the example uses get_cache_info which has limited support on AMD. To get cache sizes reliably on AMD you might want to use other functions like https://docs.rs/raw-cpuid/latest/raw_cpuid/struct.CpuId.html#method.get_l1_cache_and_tlb_info and https://docs.rs/raw-cpuid/latest/raw_cpuid/struct.CpuId.html#method.get_l2_l3_cache_and_tlb_info

@gz gz added the question label Oct 8, 2024
@Umio-Yasuno
Copy link
Contributor

So far so good, but I am using AMD Ryzen 7800X3D 8-Core Processor. Official spec and windows system monitor both report L2 cache size as 512KB.

L1 cache?
7800X3D has the L2 cache of 8MB (1MB per core).

https://www.amd.com/en/products/processors/desktops/ryzen/7000-series/amd-ryzen-7-7800x3d.html

The total cache count can be calculated as <max threads> / max_cores_for_cache for AMD Ryzen.
If you want the total cache size, use <cache size> * (<max threads> / max_cores_for_cache) to calculate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants