RISC-V instruction to write dirty cache line to next level of cache

1.3k views Asked by At

Are there any RISC-V instructions to write-back dirty cache line to next level of cache, or to main memory, like clwb in x86 or cvac in ARMv8-A?

I want to ensure commit to non-volatile persistent memory.

My intention is to adapt ARMv8_A code mentioned below for RISC-V and execute it in Gem5.

#code

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <stdint.h>

void clean_invalidate(uint64_t addr){
        uint64_t ctr_el0 = 0;
        if(ctr_el0 == 0)
                asm volatile("mrs %0, ctr_el0":"=r"(ctr_el0)::);
        const size_t dcache_line_size = 4 << ((ctr_el0 >>16)&15);
        addr = addr & ~(dcache_line_size - 1);
        asm volatile("dc cvau, %0"::"r"(addr):);
}


int main(){
        int a[1000];
        int index = 0;
        uint64_t addr = 0;
        double time_spend = 0.0;
        clock_t begin = clock();
        for(int i=0;i<100;i++){
                index = rand()%1000;
                a[index] = index;
                addr = (uint64_t)(&a[index]);
                asm volatile("dsb ish");
                clean_invalidate(addr);
                asm volatile("dsb ish");
                int b = a[index];
        }
        clock_t end = clock();
        time_spend = (double)(end-begin)/CLOCKS_PER_SEC;
        printf("Time:%f\n",time_spend);
        return 0;
}
1

There are 1 answers

0
Hadi Brais On BEST ANSWER

No, the latest version of RISC-V doesn't support data cache line flushing instructions (or even uncacheable writes).

In the presentation you linked to in the comments, the person is only proposing necessary changes to RISC-V to support persistent memory. That person is not affiliated with the RISC-V organization. Officially, there is no indication that any such instructions will be added soon to the ISA.

What you can do is implement clwb (and probably sfence too) yourself in the gem5 simulator, or switch to an ISA that already supports persistent memory.