ionic: use index not pointer for queue tracking
Use index counters rather than pointers for tracking head and tail in the queues to save a little memory and to perhaps slightly faster queue processing. Signed-off-by: Shannon Nelson <snelson@pensando.io> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
ea5a8b09dc
commit
f1d2e894f1
7 changed files with 129 additions and 88 deletions
|
|
@ -482,7 +482,7 @@ int ionic_cq_init(struct ionic_lif *lif, struct ionic_cq *cq,
|
|||
cq->bound_intr = intr;
|
||||
cq->num_descs = num_descs;
|
||||
cq->desc_size = desc_size;
|
||||
cq->tail = cq->info;
|
||||
cq->tail_idx = 0;
|
||||
cq->done_color = 1;
|
||||
|
||||
cur = cq->info;
|
||||
|
|
@ -522,15 +522,18 @@ unsigned int ionic_cq_service(struct ionic_cq *cq, unsigned int work_to_do,
|
|||
ionic_cq_cb cb, ionic_cq_done_cb done_cb,
|
||||
void *done_arg)
|
||||
{
|
||||
struct ionic_cq_info *cq_info;
|
||||
unsigned int work_done = 0;
|
||||
|
||||
if (work_to_do == 0)
|
||||
return 0;
|
||||
|
||||
while (cb(cq, cq->tail)) {
|
||||
if (cq->tail->last)
|
||||
cq_info = &cq->info[cq->tail_idx];
|
||||
while (cb(cq, cq_info)) {
|
||||
if (cq->tail_idx == cq->num_descs - 1)
|
||||
cq->done_color = !cq->done_color;
|
||||
cq->tail = cq->tail->next;
|
||||
cq->tail_idx = (cq->tail_idx + 1) & (cq->num_descs - 1);
|
||||
cq_info = &cq->info[cq->tail_idx];
|
||||
DEBUG_STATS_CQE_CNT(cq);
|
||||
|
||||
if (++work_done >= work_to_do)
|
||||
|
|
@ -565,8 +568,8 @@ int ionic_q_init(struct ionic_lif *lif, struct ionic_dev *idev,
|
|||
q->num_descs = num_descs;
|
||||
q->desc_size = desc_size;
|
||||
q->sg_desc_size = sg_desc_size;
|
||||
q->tail = q->info;
|
||||
q->head = q->tail;
|
||||
q->tail_idx = 0;
|
||||
q->head_idx = 0;
|
||||
q->pid = pid;
|
||||
|
||||
snprintf(q->name, sizeof(q->name), "L%d-%s%u", lif->index, name, index);
|
||||
|
|
@ -614,19 +617,22 @@ void ionic_q_post(struct ionic_queue *q, bool ring_doorbell, ionic_desc_cb cb,
|
|||
void *cb_arg)
|
||||
{
|
||||
struct device *dev = q->lif->ionic->dev;
|
||||
struct ionic_desc_info *desc_info;
|
||||
struct ionic_lif *lif = q->lif;
|
||||
|
||||
q->head->cb = cb;
|
||||
q->head->cb_arg = cb_arg;
|
||||
q->head = q->head->next;
|
||||
desc_info = &q->info[q->head_idx];
|
||||
desc_info->cb = cb;
|
||||
desc_info->cb_arg = cb_arg;
|
||||
|
||||
q->head_idx = (q->head_idx + 1) & (q->num_descs - 1);
|
||||
|
||||
dev_dbg(dev, "lif=%d qname=%s qid=%d qtype=%d p_index=%d ringdb=%d\n",
|
||||
q->lif->index, q->name, q->hw_type, q->hw_index,
|
||||
q->head->index, ring_doorbell);
|
||||
q->head_idx, ring_doorbell);
|
||||
|
||||
if (ring_doorbell)
|
||||
ionic_dbell_ring(lif->kern_dbpage, q->hw_type,
|
||||
q->dbval | q->head->index);
|
||||
q->dbval | q->head_idx);
|
||||
}
|
||||
|
||||
static bool ionic_q_is_posted(struct ionic_queue *q, unsigned int pos)
|
||||
|
|
@ -634,8 +640,8 @@ static bool ionic_q_is_posted(struct ionic_queue *q, unsigned int pos)
|
|||
unsigned int mask, tail, head;
|
||||
|
||||
mask = q->num_descs - 1;
|
||||
tail = q->tail->index;
|
||||
head = q->head->index;
|
||||
tail = q->tail_idx;
|
||||
head = q->head_idx;
|
||||
|
||||
return ((pos - tail) & mask) < ((head - tail) & mask);
|
||||
}
|
||||
|
|
@ -648,18 +654,18 @@ void ionic_q_service(struct ionic_queue *q, struct ionic_cq_info *cq_info,
|
|||
void *cb_arg;
|
||||
|
||||
/* check for empty queue */
|
||||
if (q->tail->index == q->head->index)
|
||||
if (q->tail_idx == q->head_idx)
|
||||
return;
|
||||
|
||||
/* stop index must be for a descriptor that is not yet completed */
|
||||
if (unlikely(!ionic_q_is_posted(q, stop_index)))
|
||||
dev_err(q->lif->ionic->dev,
|
||||
"ionic stop is not posted %s stop %u tail %u head %u\n",
|
||||
q->name, stop_index, q->tail->index, q->head->index);
|
||||
q->name, stop_index, q->tail_idx, q->head_idx);
|
||||
|
||||
do {
|
||||
desc_info = q->tail;
|
||||
q->tail = desc_info->next;
|
||||
desc_info = &q->info[q->tail_idx];
|
||||
q->tail_idx = (q->tail_idx + 1) & (q->num_descs - 1);
|
||||
|
||||
cb = desc_info->cb;
|
||||
cb_arg = desc_info->cb_arg;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue