Skip to content

Commit

Permalink
clock_timekeeping: remove enter_critical_section in sched/clock/clock…
Browse files Browse the repository at this point in the history
…_timekeeping.c

reason:
We would like to replace the critical section with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
  • Loading branch information
hujun260 authored and xiaoxiang781216 committed Jan 12, 2025
1 parent 2149d89 commit a2d4d74
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions sched/clock/clock_timekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static struct timespec g_clock_wall_time;
static uint64_t g_clock_last_counter;
static uint64_t g_clock_mask;
static long g_clock_adjust;
static spinlock_t g_clock_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
Expand All @@ -72,7 +73,7 @@ static int clock_get_current_time(FAR struct timespec *ts,
time_t sec;
int ret;

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);

ret = up_timer_gettick(&counter);
if (ret < 0)
Expand All @@ -96,7 +97,7 @@ static int clock_get_current_time(FAR struct timespec *ts,
ts->tv_sec = base->tv_sec + sec;

errout_in_critical_section:
leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);
return ret;
}

Expand All @@ -123,7 +124,7 @@ int clock_timekeeping_set_wall_time(FAR const struct timespec *ts)
uint64_t counter;
int ret;

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);

ret = up_timer_gettick(&counter);
if (ret < 0)
Expand All @@ -137,7 +138,7 @@ int clock_timekeeping_set_wall_time(FAR const struct timespec *ts)
g_clock_last_counter = counter;

errout_in_critical_section:
leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);
return ret;
}

Expand Down Expand Up @@ -188,7 +189,7 @@ int adjtime(FAR const struct timeval *delta, FAR struct timeval *olddelta)
return -1;
}

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);

adjust_usec = delta->tv_sec * USEC_PER_SEC + delta->tv_usec;

Expand All @@ -199,7 +200,7 @@ int adjtime(FAR const struct timeval *delta, FAR struct timeval *olddelta)

g_clock_adjust = adjust_usec;

leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);

return OK;
}
Expand All @@ -217,7 +218,7 @@ void clock_update_wall_time(void)
time_t sec;
int ret;

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);

ret = up_timer_gettick(&counter);
if (ret < 0)
Expand Down Expand Up @@ -271,7 +272,7 @@ void clock_update_wall_time(void)
g_clock_last_counter = counter;

errout_in_critical_section:
leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);
}

/****************************************************************************
Expand All @@ -280,6 +281,9 @@ void clock_update_wall_time(void)

void clock_inittimekeeping(FAR const struct timespec *tp)
{
irqstate_t flags;

flags = spin_lock_irqsave(&g_clock_lock);
up_timer_getmask(&g_clock_mask);

if (tp)
Expand All @@ -292,6 +296,7 @@ void clock_inittimekeeping(FAR const struct timespec *tp)
}

up_timer_gettick(&g_clock_last_counter);
spin_unlock_irqrestore(&g_clock_lock, flags);
}

#endif /* CONFIG_CLOCK_TIMEKEEPING */

0 comments on commit a2d4d74

Please sign in to comment.