[tip:timers/core] usb/gadget/NCM: Replace tasklet with softirq hrtimer

2018-01-16 Thread tip-bot for Thomas Gleixner
Commit-ID:  b1a31a5f5f27ff8aba42b545a1c721941f735107
Gitweb: https://git.kernel.org/tip/b1a31a5f5f27ff8aba42b545a1c721941f735107
Author: Thomas Gleixner 
AuthorDate: Thu, 21 Dec 2017 11:42:04 +0100
Committer:  Ingo Molnar 
CommitDate: Tue, 16 Jan 2018 09:51:23 +0100

usb/gadget/NCM: Replace tasklet with softirq hrtimer

The tx_tasklet tasklet is used in invoke the hrtimer (task_timer) in
softirq context. This can be also achieved without the tasklet but
with HRTIMER_MODE_SOFT as hrtimer mode.

Signed-off-by: Thomas Gleixner 
Signed-off-by: Anna-Maria Gleixner 
Acked-by: Felipe Balbi 
Cc: Christoph Hellwig 
Cc: Felipe Balbi 
Cc: John Stultz 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: keesc...@chromium.org
Cc: linux-...@vger.kernel.org
Link: http://lkml.kernel.org/r/20171221104205.7269-36-anna-ma...@linutronix.de
Signed-off-by: Ingo Molnar 
---
 drivers/usb/gadget/function/f_ncm.c | 30 +++---
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/gadget/function/f_ncm.c 
b/drivers/usb/gadget/function/f_ncm.c
index c5bce8e..5780fba 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -73,9 +73,7 @@ struct f_ncm {
struct sk_buff  *skb_tx_ndp;
u16 ndp_dgram_count;
booltimer_force_tx;
-   struct tasklet_struct   tx_tasklet;
struct hrtimer  task_timer;
-
booltimer_stopping;
 };
 
@@ -1104,7 +1102,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 
/* Delay the timer. */
hrtimer_start(>task_timer, TX_TIMEOUT_NSECS,
- HRTIMER_MODE_REL);
+ HRTIMER_MODE_REL_SOFT);
 
/* Add the datagram position entries */
ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len);
@@ -1148,17 +1146,15 @@ err:
 }
 
 /*
- * This transmits the NTB if there are frames waiting.
+ * The transmit should only be run if no skb data has been sent
+ * for a certain duration.
  */
-static void ncm_tx_tasklet(unsigned long data)
+static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data)
 {
-   struct f_ncm*ncm = (void *)data;
-
-   if (ncm->timer_stopping)
-   return;
+   struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer);
 
/* Only send if data is available. */
-   if (ncm->skb_tx_data) {
+   if (!ncm->timer_stopping && ncm->skb_tx_data) {
ncm->timer_force_tx = true;
 
/* XXX This allowance of a NULL skb argument to ndo_start_xmit
@@ -1171,16 +1167,6 @@ static void ncm_tx_tasklet(unsigned long data)
 
ncm->timer_force_tx = false;
}
-}
-
-/*
- * The transmit should only be run if no skb data has been sent
- * for a certain duration.
- */
-static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data)
-{
-   struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer);
-   tasklet_schedule(>tx_tasklet);
return HRTIMER_NORESTART;
 }
 
@@ -1513,8 +1499,7 @@ static int ncm_bind(struct usb_configuration *c, struct 
usb_function *f)
ncm->port.open = ncm_open;
ncm->port.close = ncm_close;
 
-   tasklet_init(>tx_tasklet, ncm_tx_tasklet, (unsigned long) ncm);
-   hrtimer_init(>task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+   hrtimer_init(>task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
ncm->task_timer.function = ncm_tx_timeout;
 
DBG(cdev, "CDC Network: %s speed IN/%s OUT/%s NOTIFY/%s\n",
@@ -1623,7 +1608,6 @@ static void ncm_unbind(struct usb_configuration *c, 
struct usb_function *f)
DBG(c->cdev, "ncm unbind\n");
 
hrtimer_cancel(>task_timer);
-   tasklet_kill(>tx_tasklet);
 
ncm_string_defs[0].id = 0;
usb_free_all_descriptors(f);


[tip:timers/core] usb/gadget/NCM: Replace tasklet with softirq hrtimer

2018-01-16 Thread tip-bot for Thomas Gleixner
Commit-ID:  b1a31a5f5f27ff8aba42b545a1c721941f735107
Gitweb: https://git.kernel.org/tip/b1a31a5f5f27ff8aba42b545a1c721941f735107
Author: Thomas Gleixner 
AuthorDate: Thu, 21 Dec 2017 11:42:04 +0100
Committer:  Ingo Molnar 
CommitDate: Tue, 16 Jan 2018 09:51:23 +0100

usb/gadget/NCM: Replace tasklet with softirq hrtimer

The tx_tasklet tasklet is used in invoke the hrtimer (task_timer) in
softirq context. This can be also achieved without the tasklet but
with HRTIMER_MODE_SOFT as hrtimer mode.

Signed-off-by: Thomas Gleixner 
Signed-off-by: Anna-Maria Gleixner 
Acked-by: Felipe Balbi 
Cc: Christoph Hellwig 
Cc: Felipe Balbi 
Cc: John Stultz 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: keesc...@chromium.org
Cc: linux-...@vger.kernel.org
Link: http://lkml.kernel.org/r/20171221104205.7269-36-anna-ma...@linutronix.de
Signed-off-by: Ingo Molnar 
---
 drivers/usb/gadget/function/f_ncm.c | 30 +++---
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/gadget/function/f_ncm.c 
b/drivers/usb/gadget/function/f_ncm.c
index c5bce8e..5780fba 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -73,9 +73,7 @@ struct f_ncm {
struct sk_buff  *skb_tx_ndp;
u16 ndp_dgram_count;
booltimer_force_tx;
-   struct tasklet_struct   tx_tasklet;
struct hrtimer  task_timer;
-
booltimer_stopping;
 };
 
@@ -1104,7 +1102,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 
/* Delay the timer. */
hrtimer_start(>task_timer, TX_TIMEOUT_NSECS,
- HRTIMER_MODE_REL);
+ HRTIMER_MODE_REL_SOFT);
 
/* Add the datagram position entries */
ntb_ndp = skb_put_zero(ncm->skb_tx_ndp, dgram_idx_len);
@@ -1148,17 +1146,15 @@ err:
 }
 
 /*
- * This transmits the NTB if there are frames waiting.
+ * The transmit should only be run if no skb data has been sent
+ * for a certain duration.
  */
-static void ncm_tx_tasklet(unsigned long data)
+static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data)
 {
-   struct f_ncm*ncm = (void *)data;
-
-   if (ncm->timer_stopping)
-   return;
+   struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer);
 
/* Only send if data is available. */
-   if (ncm->skb_tx_data) {
+   if (!ncm->timer_stopping && ncm->skb_tx_data) {
ncm->timer_force_tx = true;
 
/* XXX This allowance of a NULL skb argument to ndo_start_xmit
@@ -1171,16 +1167,6 @@ static void ncm_tx_tasklet(unsigned long data)
 
ncm->timer_force_tx = false;
}
-}
-
-/*
- * The transmit should only be run if no skb data has been sent
- * for a certain duration.
- */
-static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data)
-{
-   struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer);
-   tasklet_schedule(>tx_tasklet);
return HRTIMER_NORESTART;
 }
 
@@ -1513,8 +1499,7 @@ static int ncm_bind(struct usb_configuration *c, struct 
usb_function *f)
ncm->port.open = ncm_open;
ncm->port.close = ncm_close;
 
-   tasklet_init(>tx_tasklet, ncm_tx_tasklet, (unsigned long) ncm);
-   hrtimer_init(>task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+   hrtimer_init(>task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
ncm->task_timer.function = ncm_tx_timeout;
 
DBG(cdev, "CDC Network: %s speed IN/%s OUT/%s NOTIFY/%s\n",
@@ -1623,7 +1608,6 @@ static void ncm_unbind(struct usb_configuration *c, 
struct usb_function *f)
DBG(c->cdev, "ncm unbind\n");
 
hrtimer_cancel(>task_timer);
-   tasklet_kill(>tx_tasklet);
 
ncm_string_defs[0].id = 0;
usb_free_all_descriptors(f);