Skip to content

Commit 0cc6794

Browse files
sudeep-hollaJassiBrar
authored andcommitted
mailbox: switch to hrtimer for tx_complete polling
The mailbox core uses jiffy based timer to handle polling for the transmit completion. If the client/protocol have/support notification of the last packet transmit completion via ACK packet, then we tick the Tx state machine immediately in the callback. However if the client doesn't support that mechanism we might end-up waiting for atleast a jiffy even though the remote is ready to receive the next request. This patch switches the timer used for that polling from jiffy-based to hrtimer-based so that we can support polling at much higher time resolution. Reported-and-suggested-by: Juri Lelli <[email protected]> Signed-off-by: Sudeep Holla <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent 63d5e12 commit 0cc6794

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

drivers/mailbox/mailbox.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
static LIST_HEAD(mbox_cons);
2727
static DEFINE_MUTEX(con_mutex);
2828

29-
static void poll_txdone(unsigned long data);
30-
3129
static int add_to_rbuf(struct mbox_chan *chan, void *mssg)
3230
{
3331
int idx;
@@ -88,7 +86,9 @@ static void msg_submit(struct mbox_chan *chan)
8886
spin_unlock_irqrestore(&chan->lock, flags);
8987

9088
if (!err && (chan->txdone_method & TXDONE_BY_POLL))
91-
poll_txdone((unsigned long)chan->mbox);
89+
/* kick start the timer immediately to avoid delays */
90+
hrtimer_start(&chan->mbox->poll_hrt, ktime_set(0, 0),
91+
HRTIMER_MODE_REL);
9292
}
9393

9494
static void tx_tick(struct mbox_chan *chan, int r)
@@ -112,9 +112,10 @@ static void tx_tick(struct mbox_chan *chan, int r)
112112
complete(&chan->tx_complete);
113113
}
114114

115-
static void poll_txdone(unsigned long data)
115+
static enum hrtimer_restart txdone_hrtimer(struct hrtimer *hrtimer)
116116
{
117-
struct mbox_controller *mbox = (struct mbox_controller *)data;
117+
struct mbox_controller *mbox =
118+
container_of(hrtimer, struct mbox_controller, poll_hrt);
118119
bool txdone, resched = false;
119120
int i;
120121

@@ -130,9 +131,11 @@ static void poll_txdone(unsigned long data)
130131
}
131132
}
132133

133-
if (resched)
134-
mod_timer(&mbox->poll, jiffies +
135-
msecs_to_jiffies(mbox->txpoll_period));
134+
if (resched) {
135+
hrtimer_forward_now(hrtimer, ms_to_ktime(mbox->txpoll_period));
136+
return HRTIMER_RESTART;
137+
}
138+
return HRTIMER_NORESTART;
136139
}
137140

138141
/**
@@ -451,9 +454,9 @@ int mbox_controller_register(struct mbox_controller *mbox)
451454
txdone = TXDONE_BY_ACK;
452455

453456
if (txdone == TXDONE_BY_POLL) {
454-
mbox->poll.function = &poll_txdone;
455-
mbox->poll.data = (unsigned long)mbox;
456-
init_timer(&mbox->poll);
457+
hrtimer_init(&mbox->poll_hrt, CLOCK_MONOTONIC,
458+
HRTIMER_MODE_REL);
459+
mbox->poll_hrt.function = txdone_hrtimer;
457460
}
458461

459462
for (i = 0; i < mbox->num_chans; i++) {
@@ -495,7 +498,7 @@ void mbox_controller_unregister(struct mbox_controller *mbox)
495498
mbox_free_channel(&mbox->chans[i]);
496499

497500
if (mbox->txdone_poll)
498-
del_timer_sync(&mbox->poll);
501+
hrtimer_cancel(&mbox->poll_hrt);
499502

500503
mutex_unlock(&con_mutex);
501504
}

include/linux/mailbox_controller.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <linux/of.h>
1111
#include <linux/types.h>
12-
#include <linux/timer.h>
12+
#include <linux/hrtimer.h>
1313
#include <linux/device.h>
1414
#include <linux/completion.h>
1515

@@ -67,7 +67,8 @@ struct mbox_chan_ops {
6767
* @txpoll_period: If 'txdone_poll' is in effect, the API polls for
6868
* last TX's status after these many millisecs
6969
* @of_xlate: Controller driver specific mapping of channel via DT
70-
* @poll: API private. Used to poll for TXDONE on all channels.
70+
* @poll_hrt: API private. hrtimer used to poll for TXDONE on all
71+
* channels.
7172
* @node: API private. To hook into list of controllers.
7273
*/
7374
struct mbox_controller {
@@ -81,7 +82,7 @@ struct mbox_controller {
8182
struct mbox_chan *(*of_xlate)(struct mbox_controller *mbox,
8283
const struct of_phandle_args *sp);
8384
/* Internal to API */
84-
struct timer_list poll;
85+
struct hrtimer poll_hrt;
8586
struct list_head node;
8687
};
8788

0 commit comments

Comments
 (0)