Message ID | 1552403166-3821-12-git-send-email-sgruszka@redhat.com (mailing list archive) |
---|---|
State | RFC |
Delegated to: | Felix Fietkau |
Headers | show |
Series | mt76usb: some cleanups and optimizations | expand |
> Alloc sg table at the end of urb structure. This will increase > cache usage. > I am curious, have you observed any performance improvement doing so? > Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com> > --- > drivers/net/wireless/mediatek/mt76/usb.c | 20 ++++++++++---------- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c > index 0b9f0b5fd37d..dd487f65f44e 100644 > --- a/drivers/net/wireless/mediatek/mt76/usb.c > +++ b/drivers/net/wireless/mediatek/mt76/usb.c > @@ -336,19 +336,19 @@ static bool mt76u_check_sg(struct mt76_dev *dev) > static int > mt76u_urb_alloc(struct mt76_dev *dev, struct mt76_queue_entry *e) > { > - struct urb *urb; > + unsigned int size = sizeof(struct urb); > + > + if (dev->usb.sg_en) > + size += MT_SG_MAX_SIZE * sizeof(struct scatterlist); > > - urb = usb_alloc_urb(0, GFP_KERNEL); > - if (!urb) > + e->urb = kzalloc(size, GFP_KERNEL); > + if (!e->urb) > return -ENOMEM; > - e->urb = urb; > > - if (dev->usb.sg_en) { > - urb->sg = devm_kcalloc(dev->dev, MT_SG_MAX_SIZE, > - sizeof(urb->sg), GFP_KERNEL); > - if (!urb->sg) > - return -ENOMEM; > - } > + usb_init_urb(e->urb); > + > + if (dev->usb.sg_en) > + e->urb->sg = (struct scatterlist *)((u8 *)e->urb + sizeof(struct urb)); You can avoid u8 cast doing: (struct scatterlist *)(e->urb + 1) Regards, Lorenzo > > return 0; > } > -- > 1.9.3 >
On Tue, Mar 12, 2019 at 05:34:32PM +0100, Lorenzo Bianconi wrote: > > Alloc sg table at the end of urb structure. This will increase > > cache usage. > > > > I am curious, have you observed any performance improvement doing so? It's hard to measure that. Stressing net transfer with about 175 Mbit/s by netperf (what is max I can get) only took about 15% of CPU for me and net performance fluctuate so CPU pref stats vary too. > > - if (dev->usb.sg_en) { > > - urb->sg = devm_kcalloc(dev->dev, MT_SG_MAX_SIZE, > > - sizeof(urb->sg), GFP_KERNEL); FTR: Here is bug it should be sizeof(*urb->sg). > > - if (!urb->sg) > > - return -ENOMEM; > > - } > > + usb_init_urb(e->urb); > > + > > + if (dev->usb.sg_en) > > + e->urb->sg = (struct scatterlist *)((u8 *)e->urb + sizeof(struct urb)); > > You can avoid u8 cast doing: > (struct scatterlist *)(e->urb + 1) Cool trick! Stanislaw
diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index 0b9f0b5fd37d..dd487f65f44e 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -336,19 +336,19 @@ static bool mt76u_check_sg(struct mt76_dev *dev) static int mt76u_urb_alloc(struct mt76_dev *dev, struct mt76_queue_entry *e) { - struct urb *urb; + unsigned int size = sizeof(struct urb); + + if (dev->usb.sg_en) + size += MT_SG_MAX_SIZE * sizeof(struct scatterlist); - urb = usb_alloc_urb(0, GFP_KERNEL); - if (!urb) + e->urb = kzalloc(size, GFP_KERNEL); + if (!e->urb) return -ENOMEM; - e->urb = urb; - if (dev->usb.sg_en) { - urb->sg = devm_kcalloc(dev->dev, MT_SG_MAX_SIZE, - sizeof(urb->sg), GFP_KERNEL); - if (!urb->sg) - return -ENOMEM; - } + usb_init_urb(e->urb); + + if (dev->usb.sg_en) + e->urb->sg = (struct scatterlist *)((u8 *)e->urb + sizeof(struct urb)); return 0; }
Alloc sg table at the end of urb structure. This will increase cache usage. Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com> --- drivers/net/wireless/mediatek/mt76/usb.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)