Skip to content

Commit c91948a

Browse files
committed
sched/hrtimer: Only enable SMP related logic when in SMP mode
Improve hrtimer to only enable SMP related logic when in SMP mode to improve performance in non-SMP mode Signed-off-by: Chengdong Wang <[email protected]>
1 parent a923a94 commit c91948a

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

boards/risc-v/qemu-rv/rv-virt/configs/smp64/defconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ CONFIG_NSH_BUILTIN_APPS=y
6969
CONFIG_NSH_FILEIOSIZE=64
7070
CONFIG_RAM_SIZE=33554432
7171
CONFIG_RAM_START=0x80000000
72-
CONFIG_RR_INTERVAL=200
7372
CONFIG_SCHED_WAITPID=y
7473
CONFIG_SERIAL_UART_ARCH_MMIO=y
7574
CONFIG_SMP=y
@@ -82,3 +81,5 @@ CONFIG_SYSTEM_NSH_STACKSIZE=3072
8281
CONFIG_TESTING_OSTEST=y
8382
CONFIG_TESTING_SMP=y
8483
CONFIG_USEC_PER_TICK=1000
84+
CONFIG_HRTIMER=y
85+
CONFIG_EXAMPLES_HELLO=y

include/nuttx/hrtimer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ struct hrtimer_s
102102
hrtimer_cb func; /* Expiration callback function */
103103
FAR void *arg; /* Argument passed to callback */
104104
uint64_t expired; /* Absolute expiration time (ns) */
105+
#ifdef CONFIG_SMP
105106
uint8_t cpus; /* Number of cpus that are running the timer */
107+
#endif
106108
};
107109

108110
/****************************************************************************
@@ -142,7 +144,9 @@ void hrtimer_init(FAR hrtimer_t *hrtimer,
142144
hrtimer->state = HRTIMER_STATE_INACTIVE;
143145
hrtimer->func = func;
144146
hrtimer->arg = arg;
147+
#ifdef CONFIG_SMP
145148
hrtimer->cpus = 0;
149+
#endif
146150
}
147151

148152
/****************************************************************************

sched/hrtimer/hrtimer_cancel.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@
4141

4242
#define HRTIMER_CANCEL_SYNC_DELAY_MS 5
4343

44-
#define hrtimer_is_free(hrtimer) (((hrtimer)->state == HRTIMER_STATE_INACTIVE) && \
45-
((hrtimer)->cpus == 0))
44+
#ifdef CONFIG_SMP
45+
# define hrtimer_is_free(hrtimer) (((hrtimer)->state == HRTIMER_STATE_INACTIVE) && \
46+
((hrtimer)->cpus == 0))
47+
#else
48+
# define hrtimer_is_free(hrtimer) (((hrtimer)->state == HRTIMER_STATE_INACTIVE))
49+
#endif
4650

4751
/****************************************************************************
4852
* Public Functions

sched/hrtimer/hrtimer_process.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,14 @@ void hrtimer_process(uint64_t now)
9898
DEBUGASSERT(hrtimer->func != NULL);
9999

100100
hrtimer->state = HRTIMER_STATE_RUNNING;
101+
102+
#ifdef CONFIG_SMP
101103
hrtimer->cpus++;
102104

103105
/* cpus is a running reference counter and must never wrap */
104106

105107
DEBUGASSERT(hrtimer->cpus != 0);
108+
#endif
106109

107110
/* Leave critical section before invoking the callback */
108111

@@ -116,7 +119,9 @@ void hrtimer_process(uint64_t now)
116119

117120
flags = spin_lock_irqsave(&g_hrtimer_spinlock);
118121

122+
#ifdef CONFIG_SMP
119123
hrtimer->cpus--;
124+
#endif
120125

121126
switch (hrtimer->state)
122127
{
@@ -137,11 +142,14 @@ void hrtimer_process(uint64_t now)
137142
else
138143
{
139144
/* One-shot timer: deactivate when last instance ends */
140-
145+
#ifdef CONFIG_SMP
141146
if (hrtimer->cpus == 0)
142147
{
148+
#endif
143149
hrtimer->state = HRTIMER_STATE_INACTIVE;
150+
#ifdef CONFIG_SMP
144151
}
152+
#endif
145153
}
146154

147155
break;
@@ -151,10 +159,14 @@ void hrtimer_process(uint64_t now)
151159
{
152160
/* Timer was canceled during callback execution */
153161

162+
#ifdef CONFIG_SMP
154163
if (hrtimer->cpus == 0)
155164
{
165+
#endif
156166
hrtimer->state = HRTIMER_STATE_INACTIVE;
167+
#ifdef CONFIG_SMP
157168
}
169+
#endif
158170

159171
break;
160172
}

0 commit comments

Comments
 (0)