Skip to content

Commit

Permalink
Addede l2 cache logic
Browse files Browse the repository at this point in the history
  • Loading branch information
GlassOfWhiskey committed Nov 20, 2023
1 parent 8b0a4c2 commit 351fcd0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
44 changes: 42 additions & 2 deletions src/riscv/linux/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ void cpuinfo_riscv_linux_init(void) {
if (bitmask_all(riscv_linux_processors[processor].flags, valid_processor_mask)) {
riscv_linux_processors[processor].processor.linux_id = processor;
riscv_linux_processors[processor].flags |= CPUINFO_LINUX_FLAG_VALID;
cpuinfo_log_debug("parsed processor %"PRIu32, processor);
cpuinfo_log_debug("parsed processor %zu", processor);
}
}

Expand Down Expand Up @@ -553,12 +553,27 @@ void cpuinfo_riscv_linux_init(void) {
goto cleanup;
}

l1i = calloc(valid_processors_count, sizeof(struct cpuinfo_cache));
if (l1i == NULL) {
cpuinfo_log_error("failed to allocate %zu bytes for descriptions of %zu L1I caches",
valid_processors_count * sizeof(struct cpuinfo_cache), valid_processors_count);
goto cleanup;
}

l1d = calloc(valid_processors_count, sizeof(struct cpuinfo_cache));
if (l1d == NULL) {
cpuinfo_log_error("failed to allocate %zu bytes for descriptions of %zu L1D caches",
valid_processors_count * sizeof(struct cpuinfo_cache), valid_processors_count);
goto cleanup;
}

/* Transfer contents of processor list to ABI structures. */
size_t valid_processors_index = 0;
size_t valid_cores_index = 0;
size_t valid_clusters_index = 0;
size_t valid_packages_index = 0;
size_t valid_uarchs_index = 0;
size_t l2_count = 0;
last_uarch = cpuinfo_uarch_unknown;
for (size_t processor = 0; processor < riscv_linux_processors_count; processor++) {
if (!bitmask_all(riscv_linux_processors[processor].flags, CPUINFO_LINUX_FLAG_VALID)) {
Expand Down Expand Up @@ -612,10 +627,26 @@ void cpuinfo_riscv_linux_init(void) {
sizeof(struct cpuinfo_package));
}

/* Populate cache information structures in l1i, l1d */
struct cpuinfo_cache temp_l2 = { 0 };
cpuinfo_riscv_decode_cache(
riscv_linux_processors[processor].core.uarch,
&l1i[processor], &l1d[processor], &temp_l2);
l1i[processor].processor_start = l1d[processor].processor_start = processor;
l1i[processor].processor_count = l1d[processor].processor_count = 1;
if (temp_l2.size != 0) {
/* Assume L2 is shared by cores in the same cluster */
if (riscv_linux_processors[processor].package_leader_id == linux_id) {
l2_count += 1;
}
}

/* Commit pointers on the final structures. */
processors[valid_processors_index - 1].core = &cores[valid_cores_index - 1];
processors[valid_processors_index - 1].cluster = &clusters[valid_clusters_index - 1];
processors[valid_processors_index - 1].package = &packages[valid_packages_index - 1];
processors[valid_processors_index - 1].cache.l1i = l1i + processor;
processors[valid_processors_index - 1].cache.l1d = l1d + processor;

cores[valid_cores_index - 1].cluster = &clusters[valid_clusters_index - 1];
cores[valid_cores_index - 1].package = &packages[valid_packages_index - 1];
Expand All @@ -627,9 +658,18 @@ void cpuinfo_riscv_linux_init(void) {
linux_cpu_to_uarch_index_map[linux_id] = valid_uarchs_index - 1;
}

if (l2_count != 0) {
l2 = calloc(l2_count, sizeof(struct cpuinfo_cache));
if (l2 == NULL) {
cpuinfo_log_error("failed to allocate %zu bytes for descriptions of %zu L2 caches",
l2_count * sizeof(struct cpuinfo_cache), l2_count);
goto cleanup;
}
}

/* Populate cache information structures in l2 */
uint32_t l2_index = UINT32_MAX;
for (uint32_t processor = 0; processor < valid_processors_count; processor++) {

struct cpuinfo_cache dummy_l1i, dummy_l1d, temp_l2 = { 0 };
cpuinfo_riscv_decode_cache(
riscv_linux_processors[processor].core.uarch,
Expand Down
8 changes: 3 additions & 5 deletions src/riscv/linux/riscv-hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ void cpuinfo_riscv_linux_decode_vendor_uarch_from_hwprobe(
};
const size_t pairs_count = sizeof(pairs) / sizeof(struct riscv_hwprobe);

/* In case of failure, report unknown. */
*vendor = cpuinfo_vendor_unknown;
*uarch = cpuinfo_uarch_unknown;

/* Create a CPU set with this processor flagged. */
const size_t cpu_set_size = processor + 1;
cpu_set_t* cpu_set = CPU_ALLOC(cpu_set_size);
Expand Down Expand Up @@ -71,7 +67,9 @@ void cpuinfo_riscv_linux_decode_vendor_uarch_from_hwprobe(
void cpuinfo_riscv_linux_decode_vendor_uarch_from_hwprobe(
uint32_t processor,
enum cpuinfo_vendor vendor[restrict static 1],
enum cpuinfo_uarch uarch[restrict static 1]) {}
enum cpuinfo_uarch uarch[restrict static 1]) {
/* Do nothing */
}

#endif

0 comments on commit 351fcd0

Please sign in to comment.