irda: Use ktime_t instead of timeval
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): driver-irda-v2
v2 cover irda: Use ktime_t instead of timeval
This patch-set removed all uses of timeval and used ktime_t instead if needed, since 32-bit time types will break in the year 2038.
This patch-set also used the ktime_xxx functions accordingly. e.g.
* Used ktime_get to get the current time instead of do_gettimeofday.
* And, used ktime_us_delta to get the elapsed time directly.
Chunyan Zhang (6):
irda: Removed all unused timeval variables
irda: ali-ircc: Replace timeval with ktime_t
irda: irda-usb: Replace timeval with ktime_t
irda: nsc-ircc: Replace timeval with ktime_t
irda: stir4200: Replace timeval with ktime_t
irda: vlsi_ir: Replace timeval with ktime_t
drivers/net/irda/ali-ircc.c | 11 +++------- drivers/net/irda/ali-ircc.h | 5 ++--- drivers/net/irda/au1k_ir.c | 3 --- drivers/net/irda/irda-usb.c | 10 ++------- drivers/net/irda/irda-usb.h | 5 ++--- drivers/net/irda/kingsun-sir.c | 3 --- drivers/net/irda/ks959-sir.c | 3 --- drivers/net/irda/mcs7780.c | 2 -- drivers/net/irda/mcs7780.h | 1 - drivers/net/irda/nsc-ircc.c | 7 ++---- drivers/net/irda/nsc-ircc.h | 5 ++--- drivers/net/irda/stir4200.c | 16 ++++++-------- drivers/net/irda/via-ircc.h | 4 ---- drivers/net/irda/vlsi_ir.c | 46 ++++++++++++---------------------------- drivers/net/irda/vlsi_ir.h | 2 +- 15 files changed, 34 insertions(+), 89 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v2 1/6 irda: Removed all unused timeval variables
In the file au1k_ir.c & via-ircc.h, there were two unused definitions of the timeval type members, this commit therefore removes this unneeded code.
In other three files, the same problem is the rx_time member is only ever written, never read, so removed it entirely.
--- drivers/net/irda/au1k_ir.c | 3 --- drivers/net/irda/kingsun-sir.c | 3 --- drivers/net/irda/ks959-sir.c | 3 --- drivers/net/irda/mcs7780.c | 2 -- drivers/net/irda/mcs7780.h | 1 - drivers/net/irda/via-ircc.h | 4 ---- 6 files changed, 16 deletions(-)
drivers/net/irda/au1k_ir.c +0 -3
@@ -24,7 +24,6 @@#include <linux/interrupt.h> #include <linux/platform_device.h> #include <linux/slab.h> -#include <linux/time.h> #include <linux/types.h> #include <linux/ioport.h>
@@ -163,8 +162,6 @@ struct au1k_private {iobuff_t rx_buff;struct net_device *netdev; -struct timeval stamp; -struct timeval now;struct qos_info qos;struct irlap_cb *irlap;
drivers/net/irda/kingsun-sir.c +0 -3
@@ -114,7 +114,6 @@ struct kingsun_cb {(usually 8) */ iobuff_t rx_buff;/* receive unwrap state machine */ -struct timeval rx_time;spinlock_t lock;int receiving;
@@ -235,7 +234,6 @@ static void kingsun_rcv_irq(struct urb *urb) &kingsun->netdev->stats, &kingsun->rx_buff, bytes[i]); } -do_gettimeofday (&kingsun->rx_time); kingsun->receiving = (kingsun->rx_buff.state !=OUTSIDE_FRAME ) ?1 :0 ;
@@ -273,7 +271,6 @@ static int kingsun_net_open(struct net_device *netdev)skb_reserve (kingsun->rx_buff.skb,1 ); kingsun->rx_buff.head = kingsun->rx_buff.skb->data; -do_gettimeofday (&kingsun->rx_time); kingsun->rx_urb =usb_alloc_urb (0 ,GFP_KERNEL );if (!kingsun->rx_urb)
drivers/net/irda/ks959-sir.c +0 -3
@@ -187,7 +187,6 @@ struct ks959_cb {__u8 *rx_buf;__u8 rx_variable_xormask;iobuff_t rx_unwrap_buff; -struct timeval rx_time;struct usb_ctrlrequest *speed_setuprequest;struct urb *speed_urb;
@@ -476,7 +475,6 @@ static void ks959_rcv_irq(struct urb *urb) bytes[i]); } } -do_gettimeofday (&kingsun->rx_time); kingsun->receiving = (kingsun->rx_unwrap_buff.state !=OUTSIDE_FRAME ) ?1 :0 ; }
@@ -514,7 +512,6 @@ static int ks959_net_open(struct net_device *netdev)skb_reserve (kingsun->rx_unwrap_buff.skb,1 ); kingsun->rx_unwrap_buff.head = kingsun->rx_unwrap_buff.skb->data; -do_gettimeofday (&kingsun->rx_time); kingsun->rx_urb =usb_alloc_urb (0 ,GFP_KERNEL );if (!kingsun->rx_urb)
drivers/net/irda/mcs7780.c +0 -2
@@ -722,7 +722,6 @@ static int mcs_net_open(struct net_device *netdev)skb_reserve (mcs->rx_buff.skb,1 ); mcs->rx_buff.head = mcs->rx_buff.skb->data; -do_gettimeofday (&mcs->rx_time);/* * Now that everything should be initialized properly,
@@ -799,7 +798,6 @@ static void mcs_receive_irq(struct urb *urb)mcs_unwrap_fir (mcs, urb->transfer_buffer, urb->actual_length); } -do_gettimeofday (&mcs->rx_time); } ret =usb_submit_urb (urb,GFP_ATOMIC );
drivers/net/irda/mcs7780.h +0 -1
@@ -116,7 +116,6 @@ struct mcs_cb {__u8 *fifo_status;iobuff_t rx_buff;/* receive unwrap state machine */ -struct timeval rx_time;spinlock_t lock;int receiving;
drivers/net/irda/via-ircc.h +0 -4
@@ -29,7 +29,6 @@ this program; if not, see <http://www.gnu.org/licenses/>.********************************************************************/ #ifndef via_IRCC_H#define via_IRCC_H -#include <linux/time.h> #include <linux/spinlock.h> #include <linux/pm.h> #include <linux/types.h>
@@ -106,9 +105,6 @@ struct via_ircc_cb {__u8 ier;/* Interrupt enable register */ -struct timeval stamp; -struct timeval now; -spinlock_t lock;/* For serializing operations */ __u32 flags;/* Interface flags */
Signature · 1 line
1.7.9.5
PATCH v2 2/6 irda: ali-ircc: Replace timeval with ktime_t
In reply to Chunyan ZhangThe ali ircc driver uses 'timeval', which we try to remove in the kernel because all 32-bit time types will break in the year 2038.
This patch also changes do_gettimeofday() to ktime_get() accordingly, since ktime_get returns a ktime_t, but do_gettimeofday returns a struct timeval, and the other reason is that ktime_get() uses the monotonic clock.
This patch uses ktime_us_delta to get the elapsed time, and in this way it no longer needs to check for the overflow, because ktime_us_delta returns time difference of microsecond.
--- drivers/net/irda/ali-ircc.c | 11 +++-------- drivers/net/irda/ali-ircc.h | 5 ++--- 2 files changed, 5 insertions(+), 11 deletions(-)
drivers/net/irda/ali-ircc.c +3 -8
@@ -1462,17 +1462,12 @@ static netdev_tx_t ali_ircc_fir_hard_xmit(struct sk_buff *skb,if (mtt) {/* Check how much time we have used already */ -do_gettimeofday (&self->now); - - diff = self->now.tv_usec - self->stamp.tv_usec; + diff =ktime_us_delta (ktime_get (), self->stamp);/* self->stamp is set from ali_ircc_dma_receive_complete() */ pr_debug ("%s(), ******* diff = %d *******\n" , __func__, diff); - -if (diff <0 ) - diff +=1000000 ; - +/* Check if the mtt is larger than the time we have * already used by all the protocol processing */
@@ -1884,7 +1879,7 @@ static int ali_ircc_dma_receive_complete(struct ali_ircc_cb *self)* reduce the min turn time a bit since we will know * how much time we have used for protocol processing */ -do_gettimeofday (&self->stamp); + self->stamp =ktime_get (); skb =dev_alloc_skb (len+1 );if (skb ==NULL )
drivers/net/irda/ali-ircc.h +2 -3
@@ -22,7 +22,7 @@#ifndef ALI_IRCC_H #define ALI_IRCC_H -#include <linux/time.h> +#include <linux/ktime.h> #include <linux/spinlock.h> #include <linux/pm.h>
@@ -209,8 +209,7 @@ struct ali_ircc_cb {unsigned char rcvFramesOverflow; -struct timeval stamp; -struct timeval now; +ktime_t stamp;spinlock_t lock;/* For serializing operations */
Signature · 1 line
1.7.9.5
PATCH v2 3/6 irda: irda-usb: Replace timeval with ktime_t
In reply to Chunyan ZhangThe irda usb driver uses 'timeval', which we try to remove in the kernel because all 32-bit time types will break in the year 2038.
This patch also changes do_gettimeofday() to ktime_get() accordingly, since ktime_get returns a ktime_t, but do_gettimeofday returns a struct timeval, and the other reason is that ktime_get() uses the monotonic clock.
This patch uses ktime_us_delta to get the elapsed time, and in this way it no longer needs to check for the overflow, because ktime_us_delta returns time difference of microsecond.
--- drivers/net/irda/irda-usb.c | 10 ++-------- drivers/net/irda/irda-usb.h | 5 ++--- 2 files changed, 4 insertions(+), 11 deletions(-)
drivers/net/irda/irda-usb.c +2 -8
@@ -495,18 +495,12 @@ static netdev_tx_t irda_usb_hard_xmit(struct sk_buff *skb, mtt =irda_get_mtt (skb);if (mtt) {int diff; -do_gettimeofday (&self->now); - diff = self->now.tv_usec - self->stamp.tv_usec; + diff =ktime_us_delta (ktime_get (), self->stamp);#ifdef IU_USB_MIN_RTT /* Factor in USB delays -> Get rid of udelay() that * would be lost in the noise - Jean II */ diff +=IU_USB_MIN_RTT ;#endif /* IU_USB_MIN_RTT */ -/* If the usec counter did wraparound, the diff will -* go negative (tv_usec is a long), so we need to -* correct it by one second. Jean II */ -if (diff <0 ) - diff +=1000000 ;/* Check if the mtt is larger than the time we have * already used by all the protocol processing
@@ -869,7 +863,7 @@ static void irda_usb_receive(struct urb *urb)* reduce the min turn time a bit since we will know * how much time we have used for protocol processing */ -do_gettimeofday (&self->stamp); + self->stamp =ktime_get ();/* Check if we need to copy the data to a new skb or not. * For most frames, we use ZeroCopy and pass the already
drivers/net/irda/irda-usb.h +2 -3
@@ -29,7 +29,7 @@* *****************************************************************************/ -#include <linux/time.h> +#include <linux/ktime.h> #include <net/irda/irda.h> #include <net/irda/irda_device.h> /* struct irlap_cb */
@@ -157,8 +157,7 @@ struct irda_usb_cb {char *speed_buff;/* Buffer for speed changes */ char *tx_buff; -struct timeval stamp; -struct timeval now; +ktime_t stamp;spinlock_t lock;/* For serializing Tx operations */
Signature · 1 line
1.7.9.5
PATCH v2 4/6 irda: nsc-ircc: Replace timeval with ktime_t
In reply to Chunyan ZhangThe nsc ircc driver uses 'timeval', which we try to remove in the kernel because all 32-bit time types will break in the year 2038.
This patch also changes do_gettimeofday() to ktime_get() accordingly, since ktime_get returns a ktime_t, but do_gettimeofday returns a struct timeval, and the other reason is that ktime_get() uses the monotonic clock.
This patch uses ktime_us_delta to get the elapsed time, and in this way it no longer needs to check for the overflow, because ktime_us_delta returns time difference of microsecond.
--- drivers/net/irda/nsc-ircc.c | 7 ++----- drivers/net/irda/nsc-ircc.h | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-)
drivers/net/irda/nsc-ircc.c +2 -5
@@ -1501,10 +1501,7 @@ static netdev_tx_t nsc_ircc_hard_xmit_fir(struct sk_buff *skb, mtt =irda_get_mtt (skb);if (mtt) {/* Check how much time we have used already */ -do_gettimeofday (&self->now); - diff = self->now.tv_usec - self->stamp.tv_usec; -if (diff <0 ) - diff +=1000000 ; + diff =ktime_us_delta (ktime_get (), self->stamp);/* Check if the mtt is larger than the time we have * already used by all the protocol processing
@@ -1867,7 +1864,7 @@ static int nsc_ircc_dma_receive_complete(struct nsc_ircc_cb *self, int iobase)* reduce the min turn time a bit since we will know * how much time we have used for protocol processing */ -do_gettimeofday (&self->stamp); + self->stamp =ktime_get (); skb =dev_alloc_skb (len+1 );if (skb ==NULL ) {
drivers/net/irda/nsc-ircc.h +2 -3
@@ -28,7 +28,7 @@#ifndef NSC_IRCC_H #define NSC_IRCC_H -#include <linux/time.h> +#include <linux/ktime.h> #include <linux/spinlock.h> #include <linux/pm.h>
@@ -263,8 +263,7 @@ struct nsc_ircc_cb {__u8 ier;/* Interrupt enable register */ -struct timeval stamp; -struct timeval now; +ktime_t stamp;spinlock_t lock;/* For serializing operations */
Signature · 1 line
1.7.9.5
PATCH v2 5/6 irda: stir4200: Replace timeval with ktime_t
In reply to Chunyan ZhangThe stir4200 driver uses 'timeval', which we try to remove in the kernel because all 32-bit time types will break in the year 2038.
This patch also changes do_gettimeofday() to ktime_get() accordingly, since ktime_get returns a ktime_t, but do_gettimeofday returns a struct timeval, and the other reason is that ktime_get() uses the monotonic clock.
This patch uses ktime_us_delta to get the elapsed time of microsecond.
--- drivers/net/irda/stir4200.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/net/irda/stir4200.c +7 -9
@@ -40,6 +40,7 @@#include <linux/moduleparam.h> #include <linux/kernel.h> +#include <linux/ktime.h> #include <linux/types.h> #include <linux/time.h> #include <linux/skbuff.h>
@@ -174,7 +175,7 @@ struct stir_cb {__u8 *fifo_status;iobuff_t rx_buff;/* receive unwrap state machine */ -struct timeval rx_time; +ktime_t rx_time;int receiving;struct urb *rx_urb; };
@@ -650,15 +651,12 @@ static int fifo_txwait(struct stir_cb *stir, int space)static void turnaround_delay (const struct stir_cb *stir,long us) {long ticks; -struct timeval now;if (us <=0 )return ; -do_gettimeofday (&now); -if (now.tv_sec - stir->rx_time.tv_sec >0 ) - us -=USEC_PER_SEC ; - us -= now.tv_usec - stir->rx_time.tv_usec; + us -=ktime_us_delta (ktime_get (), stir->rx_time); +if (us <10 )return ;
@@ -823,8 +821,8 @@ static void stir_rcv_irq(struct urb *urb)pr_debug ("receive %d\n" , urb->actual_length);unwrap_chars (stir, urb->transfer_buffer, urb->actual_length); - -do_gettimeofday (&stir->rx_time); + + stir->rx_time =ktime_get (); }/* kernel thread is stopping receiver don't resubmit */
@@ -876,7 +874,7 @@ static int stir_net_open(struct net_device *netdev)skb_reserve (stir->rx_buff.skb,1 ); stir->rx_buff.head = stir->rx_buff.skb->data; -do_gettimeofday (&stir->rx_time); + stir->rx_time =ktime_get (); stir->rx_urb =usb_alloc_urb (0 ,GFP_KERNEL );if (!stir->rx_urb)
Signature · 1 line
1.7.9.5
PATCH v2 6/6 irda: vlsi_ir: Replace timeval with ktime_t
In reply to Chunyan ZhangThe vlsi ir driver uses 'timeval', which we try to remove in the kernel because all 32-bit time types will break in the year 2038.
This patch also changes do_gettimeofday() to ktime_get() accordingly, since ktime_get returns a ktime_t, but do_gettimeofday returns a struct timeval, and the other reason is that ktime_get() uses the monotonic clock.
This patch uses ktime_us_delta to get the elapsed time of microsecond, and uses div_s64_rem to get what seconds & microseconds time elapsed for printing.
This patch also changes the function 'vlsi_hard_start_xmit' to do the same things as the others drivers, that is passing the remaining time into udelay() instead of looping until enough time has passed.
--- drivers/net/irda/vlsi_ir.c | 46 +++++++++++++------------------------------- drivers/net/irda/vlsi_ir.h | 2 +- 2 files changed, 14 insertions(+), 34 deletions(-)
drivers/net/irda/vlsi_ir.c +13 -33
@@ -33,6 +33,7 @@ MODULE_LICENSE("GPL");/********************************************************/ #include <linux/kernel.h> +#include <linux/ktime.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/pci.h>
@@ -40,9 +41,9 @@ MODULE_LICENSE("GPL");#include <linux/netdevice.h> #include <linux/skbuff.h> #include <linux/delay.h> -#include <linux/time.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> +#include <linux/math64.h> #include <linux/mutex.h> #include <asm/uaccess.h> #include <asm/byteorder.h>
@@ -180,8 +181,7 @@ static void vlsi_proc_ndev(struct seq_file *seq, struct net_device *ndev)vlsi_irda_dev_t *idev =netdev_priv (ndev);u8 byte;u16 word; -unsigned delta1, delta2; -struct timeval now; +s32 sec, usec;unsigned iobase = ndev->base_addr; seq_printf(seq, "\n%s link state: %s / %s / %s / %s\n", ndev->name,
@@ -277,17 +277,9 @@ static void vlsi_proc_ndev(struct seq_file *seq, struct net_device *ndev)seq_printf (seq,"\nsw-state:\n" );seq_printf (seq,"IrPHY setup: %d baud - %s encoding\n" , idev->baud, (idev->mode==IFF_SIR )?"SIR" :((idev->mode==IFF_MIR )?"MIR" :"FIR" )); -do_gettimeofday (&now); -if (now.tv_usec >= idev->last_rx.tv_usec) { - delta2 = now.tv_usec - idev->last_rx.tv_usec; - delta1 =0 ; - } -else { - delta2 =1000000 + now.tv_usec - idev->last_rx.tv_usec; - delta1 =1 ; - } -seq_printf (seq,"last rx: %lu.%06u sec\n" , - now.tv_sec - idev->last_rx.tv_sec - delta1, delta2); + sec =div_s64_rem (ktime_us_delta (ktime_get (), idev->last_rx), +USEC_PER_SEC , &usec); +seq_printf (seq,"last rx: %ul.%06u sec\n" , sec, usec); seq_printf(seq, "RX: packets=%lu / bytes=%lu / errors=%lu / dropped=%lu", ndev->stats.rx_packets, ndev->stats.rx_bytes, ndev->stats.rx_errors,
@@ -661,7 +653,7 @@ static void vlsi_rx_interrupt(struct net_device *ndev) } } -do_gettimeofday (&idev->last_rx);/* remember "now" for later mtt delay */ + idev->last_rx =ktime_get ();/* remember "now" for later mtt delay */ vlsi_fill_rx (r);
@@ -858,9 +850,8 @@ static netdev_tx_t vlsi_hard_start_xmit(struct sk_buff *skb,unsigned iobase = ndev->base_addr;u8 status;u16 config; -int mtt; +int mtt, diff;int len, speed; -struct timeval now, ready;char *msg =NULL ; speed =irda_get_next_speed (skb);
@@ -940,21 +931,10 @@ static netdev_tx_t vlsi_hard_start_xmit(struct sk_buff *skb,spin_unlock_irqrestore (&idev->lock, flags);if ((mtt =irda_get_mtt (skb)) >0 ) { - - ready.tv_usec = idev->last_rx.tv_usec + mtt; - ready.tv_sec = idev->last_rx.tv_sec; -if (ready.tv_usec >=1000000 ) { - ready.tv_usec -=1000000 ; - ready.tv_sec++;/* IrLAP 1.1: mtt always < 1 sec */ - } -for (;;) { -do_gettimeofday (&now); -if (now.tv_sec > ready.tv_sec || - (now.tv_sec==ready.tv_sec && now.tv_usec>=ready.tv_usec)) -break ; -udelay (100 ); + diff =ktime_us_delta (ktime_get (), idev->last_rx); +if (mtt > diff) +udelay (mtt - diff);/* must not sleep here - called under netif_tx_lock! */ - } }/* tx buffer already owned by CPU due to pci_dma_sync_single_for_cpu()
@@ -1333,7 +1313,7 @@ static int vlsi_start_hw(vlsi_irda_dev_t *idev)vlsi_fill_rx (idev->rx_ring); -do_gettimeofday (&idev->last_rx);/* first mtt may start from now on */ + idev->last_rx =ktime_get ();/* first mtt may start from now on */ outw (0 , iobase+VLSI_PIO_PROMPT );/* kick hw state machine */
@@ -1520,7 +1500,7 @@ static int vlsi_open(struct net_device *ndev)if (!idev->irlap) goto errout_free_ring; -do_gettimeofday (&idev->last_rx);/* first mtt may start from now on */ + idev->last_rx =ktime_get ();/* first mtt may start from now on */ idev->new_baud =9600 ;/* start with IrPHY using 9600(SIR) mode */
drivers/net/irda/vlsi_ir.h +1 -1
@@ -723,7 +723,7 @@ typedef struct vlsi_irda_dev {void *virtaddr;struct vlsi_ring *tx_ring, *rx_ring; -struct timeval last_rx; +ktime_t last_rx;spinlock_t lock;struct mutex mtx;
Signature · 1 line
1.7.9.5
From: Chunyan Zhang <[email protected]>
Date: Thu, 8 Jan 2015 12:01:26 +0800
Quoted 7 lines
This patch-set removed all uses of timeval and used
ktime_tinstead if needed, since 32-bit time types will break in the year 2038.This patch-set also used the
ktime_xxxfunctions accordingly. e.g.
* Usedktime_getto get the current time instead ofdo_gettimeofday.
* And, usedktime_us_deltato get the elapsed time directly.
Applied to net-next, thanks.