diff options
author | Anup Patel <anup.patel@wdc.com> | 2020-03-12 07:51:25 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2020-03-13 09:52:02 +0300 |
commit | 823345ecaed0deb7770d9bac1c881004a6410e91 (patch) | |
tree | e3b71fb186be4bebd610e796cc12f2d3f33424e6 /lib | |
parent | 16e7071f6ddd5ba69d416b5a68e4aa191fc19d3b (diff) | |
download | opensbi-823345ecaed0deb7770d9bac1c881004a6410e91.tar.xz |
include: Make sbi_current_hartid() as macro in riscv_asm.h
The sbi_current_hartid() being a regular function is quite
expensive because for callers it is a function call instead
of a direct CSR read. This patch converts sbi_current_hartid()
into a macro in riscv_asm.h.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sbi/sbi_ecall_legacy.c | 3 | ||||
-rw-r--r-- | lib/sbi/sbi_ecall_replace.c | 4 | ||||
-rw-r--r-- | lib/sbi/sbi_hart.c | 8 | ||||
-rw-r--r-- | lib/sbi/sbi_hsm.c | 4 | ||||
-rw-r--r-- | lib/sbi/sbi_init.c | 4 | ||||
-rw-r--r-- | lib/sbi/sbi_ipi.c | 2 | ||||
-rw-r--r-- | lib/sbi/sbi_system.c | 13 | ||||
-rw-r--r-- | lib/sbi/sbi_tlb.c | 2 | ||||
-rw-r--r-- | lib/sbi/sbi_trap.c | 2 | ||||
-rw-r--r-- | lib/utils/sys/clint.c | 12 |
10 files changed, 24 insertions, 30 deletions
diff --git a/lib/sbi/sbi_ecall_legacy.c b/lib/sbi/sbi_ecall_legacy.c index 9099ee3..cffef23 100644 --- a/lib/sbi/sbi_ecall_legacy.c +++ b/lib/sbi/sbi_ecall_legacy.c @@ -8,6 +8,7 @@ * Atish Patra <atish.patra@wdc.com> */ +#include <sbi/riscv_asm.h> #include <sbi/sbi_console.h> #include <sbi/sbi_ecall.h> #include <sbi/sbi_ecall_interface.h> @@ -46,7 +47,7 @@ static int sbi_ecall_legacy_handler(struct sbi_scratch *scratch, { int ret = 0; struct sbi_tlb_info tlb_info; - u32 source_hart = sbi_current_hartid(); + u32 source_hart = current_hartid(); ulong hmask = 0; switch (extid) { diff --git a/lib/sbi/sbi_ecall_replace.c b/lib/sbi/sbi_ecall_replace.c index 57760f8..21f3809 100644 --- a/lib/sbi/sbi_ecall_replace.c +++ b/lib/sbi/sbi_ecall_replace.c @@ -8,6 +8,7 @@ * Atish Patra <atish.patra@wdc.com> */ +#include <sbi/riscv_asm.h> #include <sbi/sbi_ecall.h> #include <sbi/sbi_ecall_interface.h> #include <sbi/sbi_error.h> @@ -15,7 +16,6 @@ #include <sbi/sbi_ipi.h> #include <sbi/sbi_timer.h> #include <sbi/sbi_tlb.h> -#include <sbi/riscv_asm.h> static int sbi_ecall_time_handler(struct sbi_scratch *scratch, unsigned long extid, unsigned long funcid, @@ -50,7 +50,7 @@ static int sbi_ecall_rfence_handler(struct sbi_scratch *scratch, { int ret = 0; struct sbi_tlb_info tlb_info; - u32 source_hart = sbi_current_hartid(); + u32 source_hart = current_hartid(); if (funcid >= SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA && funcid <= SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index f61a82f..aa32615 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -17,14 +17,6 @@ #include <sbi/sbi_hart.h> #include <sbi/sbi_platform.h> -/** - * Return HART ID of the caller. - */ -unsigned int sbi_current_hartid() -{ - return (u32)csr_read(CSR_MHARTID); -} - static void mstatus_init(struct sbi_scratch *scratch, u32 hartid) { const struct sbi_platform *plat = sbi_platform_ptr(scratch); diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index 5fd7855..bd58782 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -204,7 +204,7 @@ void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch) fail_exit: /* It should never reach here */ - sbi_printf("ERR: Failed stop hart [%u]\n", sbi_current_hartid()); + sbi_printf("ERR: Failed stop hart [%u]\n", current_hartid()); sbi_hart_hang(); } @@ -256,7 +256,7 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch, u32 hartid, int sbi_hsm_hart_stop(struct sbi_scratch *scratch, bool exitnow) { int oldstate; - u32 hartid = sbi_current_hartid(); + u32 hartid = current_hartid(); const struct sbi_platform *plat = sbi_platform_ptr(scratch); struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index e7afa1e..11882d6 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -273,7 +273,7 @@ static atomic_t coldboot_lottery = ATOMIC_INITIALIZER(0); void __noreturn sbi_init(struct sbi_scratch *scratch) { bool coldboot = FALSE; - u32 hartid = sbi_current_hartid(); + u32 hartid = current_hartid(); const struct sbi_platform *plat = sbi_platform_ptr(scratch); if ((SBI_HARTMASK_MAX_BITS <= hartid) || @@ -316,7 +316,7 @@ unsigned long sbi_init_count(u32 hartid) */ void __noreturn sbi_exit(struct sbi_scratch *scratch) { - u32 hartid = sbi_current_hartid(); + u32 hartid = current_hartid(); const struct sbi_platform *plat = sbi_platform_ptr(scratch); if (sbi_platform_hart_disabled(plat, hartid)) diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c index 144b04a..0781b74 100644 --- a/lib/sbi/sbi_ipi.c +++ b/lib/sbi/sbi_ipi.c @@ -176,7 +176,7 @@ void sbi_ipi_process(struct sbi_scratch *scratch) struct sbi_ipi_data *ipi_data = sbi_scratch_offset_ptr(scratch, ipi_data_off); - u32 hartid = sbi_current_hartid(); + u32 hartid = current_hartid(); sbi_platform_ipi_clear(plat, hartid); ipi_type = atomic_raw_xchg_ulong(&ipi_data->ipi_type, 0); diff --git a/lib/sbi/sbi_system.c b/lib/sbi/sbi_system.c index 461e470..061cbf6 100644 --- a/lib/sbi/sbi_system.c +++ b/lib/sbi/sbi_system.c @@ -8,6 +8,7 @@ * Nick Kossifidis <mick@ics.forth.gr> */ +#include <sbi/riscv_asm.h> #include <sbi/sbi_bitops.h> #include <sbi/sbi_hart.h> #include <sbi/sbi_hsm.h> @@ -39,12 +40,12 @@ void sbi_system_final_exit(struct sbi_scratch *scratch) void __noreturn sbi_system_reboot(struct sbi_scratch *scratch, u32 type) { ulong hbase = 0, hmask; - u32 current_hartid = sbi_current_hartid(); + u32 cur_hartid = current_hartid(); /* Send HALT IPI to every hart other than the current hart */ while (!sbi_hsm_hart_started_mask(scratch, hbase, &hmask)) { - if (hbase <= current_hartid) - hmask &= ~(1UL << (current_hartid - hbase)); + if (hbase <= cur_hartid) + hmask &= ~(1UL << (cur_hartid - hbase)); if (hmask) sbi_ipi_send_halt(scratch, hmask, hbase); hbase += BITS_PER_LONG; @@ -63,12 +64,12 @@ void __noreturn sbi_system_reboot(struct sbi_scratch *scratch, u32 type) void __noreturn sbi_system_shutdown(struct sbi_scratch *scratch, u32 type) { ulong hbase = 0, hmask; - u32 current_hartid = sbi_current_hartid(); + u32 cur_hartid = current_hartid(); /* Send HALT IPI to every hart other than the current hart */ while (!sbi_hsm_hart_started_mask(scratch, hbase, &hmask)) { - if (hbase <= current_hartid) - hmask &= ~(1UL << (current_hartid - hbase)); + if (hbase <= cur_hartid) + hmask &= ~(1UL << (cur_hartid - hbase)); if (hmask) sbi_ipi_send_halt(scratch, hmask, hbase); hbase += BITS_PER_LONG; diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 3cae7ee..a46ddfe 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -319,7 +319,7 @@ static int sbi_tlb_update(struct sbi_scratch *scratch, int ret; struct sbi_fifo *tlb_fifo_r; struct sbi_tlb_info *tinfo = data; - u32 curr_hartid = sbi_current_hartid(); + u32 curr_hartid = current_hartid(); /* * If address range to flush is too big then simply diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index b5fbc5e..b4ba2ac 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -217,7 +217,7 @@ void sbi_trap_handler(struct sbi_trap_regs *regs, { int rc = SBI_ENOTSUPP; const char *msg = "trap handler failed"; - u32 hartid = sbi_current_hartid(); + u32 hartid = current_hartid(); ulong mcause = csr_read(CSR_MCAUSE); ulong mtval = csr_read(CSR_MTVAL), mtval2 = 0, mtinst = 0; struct sbi_trap_info trap, *uptrap; diff --git a/lib/utils/sys/clint.c b/lib/utils/sys/clint.c index ec85507..22ba088 100644 --- a/lib/utils/sys/clint.c +++ b/lib/utils/sys/clint.c @@ -7,9 +7,9 @@ * Anup Patel <anup.patel@wdc.com> */ -#include <sbi/riscv_io.h> +#include <sbi/riscv_asm.h> #include <sbi/riscv_atomic.h> -#include <sbi/sbi_hart.h> +#include <sbi/riscv_io.h> #include <sbi_utils/sys/clint.h> static u32 clint_ipi_hart_count; @@ -36,7 +36,7 @@ void clint_ipi_clear(u32 target_hart) int clint_warm_ipi_init(void) { - u32 hartid = sbi_current_hartid(); + u32 hartid = current_hartid(); if (!clint_ipi_base) return -1; @@ -105,7 +105,7 @@ u64 clint_timer_value(void) void clint_timer_event_stop(void) { - u32 target_hart = sbi_current_hartid(); + u32 target_hart = current_hartid(); if (clint_time_hart_count <= target_hart) return; @@ -116,7 +116,7 @@ void clint_timer_event_stop(void) void clint_timer_event_start(u64 next_event) { - u32 target_hart = sbi_current_hartid(); + u32 target_hart = current_hartid(); if (clint_time_hart_count <= target_hart) return; @@ -127,7 +127,7 @@ void clint_timer_event_start(u64 next_event) int clint_warm_timer_init(void) { - u32 target_hart = sbi_current_hartid(); + u32 target_hart = current_hartid(); if (clint_time_hart_count <= target_hart || !clint_time_base) return -1; |