Skip to content

Commit b94396c

Browse files
SiFiveHollandavpatel
authored andcommitted
lib: utils/timer: Optimize current hart scratch access
The address of the local scratch area is stored in each hart's mscratch CSR. It is more efficient to read the CSR than to compute the address from the hart ID. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
1 parent 5c9a735 commit b94396c

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

lib/utils/timer/aclint_mtimer.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,10 @@ static u64 mtimer_value(void)
7272
static void mtimer_event_stop(void)
7373
{
7474
u32 target_hart = current_hartid();
75-
struct sbi_scratch *scratch;
75+
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
7676
struct aclint_mtimer_data *mt;
7777
u64 *time_cmp;
7878

79-
scratch = sbi_hartid_to_scratch(target_hart);
80-
if (!scratch)
81-
return;
82-
8379
mt = mtimer_get_hart_data_ptr(scratch);
8480
if (!mt)
8581
return;
@@ -92,14 +88,10 @@ static void mtimer_event_stop(void)
9288
static void mtimer_event_start(u64 next_event)
9389
{
9490
u32 target_hart = current_hartid();
95-
struct sbi_scratch *scratch;
91+
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
9692
struct aclint_mtimer_data *mt;
9793
u64 *time_cmp;
9894

99-
scratch = sbi_hartid_to_scratch(target_hart);
100-
if (!scratch)
101-
return;
102-
10395
mt = mtimer_get_hart_data_ptr(scratch);
10496
if (!mt)
10597
return;
@@ -155,13 +147,9 @@ int aclint_mtimer_warm_init(void)
155147
{
156148
u64 *mt_time_cmp;
157149
u32 target_hart = current_hartid();
158-
struct sbi_scratch *scratch;
150+
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
159151
struct aclint_mtimer_data *mt;
160152

161-
scratch = sbi_hartid_to_scratch(target_hart);
162-
if (!scratch)
163-
return SBI_ENOENT;
164-
165153
mt = mtimer_get_hart_data_ptr(scratch);
166154
if (!mt)
167155
return SBI_ENODEV;

0 commit comments

Comments
 (0)