Skip to content

Commit

Permalink
Convert important polling loops to spin at lowest SMT priority
Browse files Browse the repository at this point in the history
The pattern of calling cpu_relax() inside a polling loop does
not suit the powerpc SMT priority instructions. Prefrred is to
set a low priority then spin until break condition is reached,
then restore priority.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[stewart@linux.vnet.ibm.com: fixup lpc-uart wait_tx_room() and unit test]
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
npiggin authored and stewartsmith committed Jun 6, 2017
1 parent db9c142 commit 05b8834
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
4 changes: 3 additions & 1 deletion core/hmi.c
Expand Up @@ -599,6 +599,7 @@ static void wait_for_subcore_threads(void)
{
uint64_t timeout = 0;

smt_lowest();
while (!(*(this_cpu()->core_hmi_state_ptr) & HMI_STATE_CLEANUP_DONE)) {
/*
* We use a fixed number of TIMEOUT_LOOPS rather
Expand All @@ -616,8 +617,9 @@ static void wait_for_subcore_threads(void)
prlog(PR_DEBUG, "HMI: TB pre-recovery timeout\n");
break;
}
cpu_relax();
barrier();
}
smt_medium();
}

/*
Expand Down
5 changes: 4 additions & 1 deletion core/lock.c
Expand Up @@ -93,7 +93,10 @@ void lock(struct lock *l)
for (;;) {
if (try_lock(l))
break;
cpu_relax();
smt_lowest();
while (l->lock_val)
barrier();
smt_medium();
}
}

Expand Down
2 changes: 2 additions & 0 deletions core/test/run-timer.c
Expand Up @@ -7,6 +7,8 @@

#define mftb() (stamp)
#define sync()
#define smt_lowest()
#define smt_medium()

static uint64_t stamp, last;
struct lock;
Expand Down
5 changes: 4 additions & 1 deletion core/timer.c
Expand Up @@ -45,7 +45,10 @@ static void __sync_timer(struct timer *t)

while (t->running) {
unlock(&timer_lock);
cpu_relax();
smt_lowest();
while (t->running)
barrier();
smt_medium();
/* Should we call the pollers here ? */
lock(&timer_lock);
}
Expand Down
12 changes: 9 additions & 3 deletions hw/lpc-uart.c
Expand Up @@ -115,10 +115,16 @@ static void uart_check_tx_room(void)

static void uart_wait_tx_room(void)
{
while(!tx_room) {
while (!tx_room) {
uart_check_tx_room();
if (!tx_room)
cpu_relax();
if (!tx_room) {
smt_lowest();
do {
barrier();
uart_check_tx_room();
} while (!tx_room);
smt_medium();
}
}
}

Expand Down

0 comments on commit 05b8834

Please sign in to comment.