linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/core/dev.c jiffies cleanup
@ 2001-11-03 23:29 Andreas Dilger
  2001-11-05 16:55 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Dilger @ 2001-11-03 23:29 UTC (permalink / raw)
  To: torvalds, Alan Cox; +Cc: linux-kernel, acme

Linus, Alan,
here is the first of the jiffies cleanups, this one of the files that
Tim Schmielau flagged as "suspicious" users of jiffies.  Yes, I'm
selfish, I'll only be sending patches for now for drivers/subsystems
that I actually use.  The jiffies audit should probably become an
item on the kernel janitor list of things to do (Arnaldo CC'd).

Some places in the network code are hairy users of jiffies values,
and it is not always clear that they are being used safely, but I
can only do my best.

Where possible, I've also moved end-time calculations outside the
loop and removed some confusing uses of "now".

Cheers, Andreas
=========================================================================
--- linux/net/core/dev.c.orig	Thu Oct 25 02:55:57 2001
+++ linux/net/core/dev.c	Fri Nov  2 22:47:49 2001
@@ -1407,7 +1407,7 @@
 {
 	int this_cpu = smp_processor_id();
 	struct softnet_data *queue = &softnet_data[this_cpu];
-	unsigned long start_time = jiffies;
+	unsigned long end_time = jiffies + 1;
 	int bugdet = netdev_max_backlog;
 
 	br_read_lock(BR_NETPROTO_LOCK);
@@ -1504,7 +1504,7 @@
 
 		dev_put(rx_dev);
 
-		if (bugdet-- < 0 || jiffies - start_time > 1)
+		if (bugdet-- < 0 || time_after(jiffies, end_time))
 			goto softnet_break;
 
 #ifdef CONFIG_NET_HW_FLOWCONTROL
@@ -2585,7 +2585,7 @@
 
 int unregister_netdevice(struct net_device *dev)
 {
-	unsigned long now, warning_time;
+	unsigned long notify_time, warning_time;
 	struct net_device *d, **dp;
 
 	/* If device is running, close it first. */
@@ -2686,20 +2686,21 @@
 
 	 */
 
-	now = warning_time = jiffies;
+	notify_time = jiffies + 1*HZ;
+	warning_time = jiffies + 10*HZ;
 	while (atomic_read(&dev->refcnt) != 1) {
-		if ((jiffies - now) > 1*HZ) {
+		if (time_after(jiffies, notify_time)) {
 			/* Rebroadcast unregister notification */
 			notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev);
 		}
 		current->state = TASK_INTERRUPTIBLE;
 		schedule_timeout(HZ/4);
 		current->state = TASK_RUNNING;
-		if ((jiffies - warning_time) > 10*HZ) {
-			printk(KERN_EMERG "unregister_netdevice: waiting for %s to "
-					"become free. Usage count = %d\n",
+		if (time_after(jiffies, warning_time)) {
+			printk(KERN_EMERG "unregister_netdevice: waiting for %s"
+					" to become free. Usage count = %d\n",
 					dev->name, atomic_read(&dev->refcnt));
-			warning_time = jiffies;
+			warning_time = jiffies + 10*HZ;
 		}
 	}
 	dev_put(dev);
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] net/core/dev.c jiffies cleanup
  2001-11-03 23:29 [PATCH] net/core/dev.c jiffies cleanup Andreas Dilger
@ 2001-11-05 16:55 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2001-11-05 16:55 UTC (permalink / raw)
  To: torvalds, Alan Cox, linux-kernel; +Cc: Kernel Janitor Project

Em Sat, Nov 03, 2001 at 04:29:15PM -0700, Andreas Dilger escreveu:
> Linus, Alan,
> here is the first of the jiffies cleanups, this one of the files that
> Tim Schmielau flagged as "suspicious" users of jiffies.  Yes, I'm
> selfish, I'll only be sending patches for now for drivers/subsystems
> that I actually use.  The jiffies audit should probably become an
> item on the kernel janitor list of things to do (Arnaldo CC'd).

Sure, I'm CCing this message to the kjp mailing list so that volunteers can
work on this.
 
> Some places in the network code are hairy users of jiffies values,
> and it is not always clear that they are being used safely, but I
> can only do my best.
> 
> Where possible, I've also moved end-time calculations outside the
> loop and removed some confusing uses of "now".
> 
> Cheers, Andreas
> =========================================================================
> --- linux/net/core/dev.c.orig	Thu Oct 25 02:55:57 2001
> +++ linux/net/core/dev.c	Fri Nov  2 22:47:49 2001
> @@ -1407,7 +1407,7 @@
>  {
>  	int this_cpu = smp_processor_id();
>  	struct softnet_data *queue = &softnet_data[this_cpu];
> -	unsigned long start_time = jiffies;
> +	unsigned long end_time = jiffies + 1;
>  	int bugdet = netdev_max_backlog;
>  
>  	br_read_lock(BR_NETPROTO_LOCK);
> @@ -1504,7 +1504,7 @@
>  
>  		dev_put(rx_dev);
>  
> -		if (bugdet-- < 0 || jiffies - start_time > 1)
> +		if (bugdet-- < 0 || time_after(jiffies, end_time))
>  			goto softnet_break;
>  
>  #ifdef CONFIG_NET_HW_FLOWCONTROL
> @@ -2585,7 +2585,7 @@
>  
>  int unregister_netdevice(struct net_device *dev)
>  {
> -	unsigned long now, warning_time;
> +	unsigned long notify_time, warning_time;
>  	struct net_device *d, **dp;
>  
>  	/* If device is running, close it first. */
> @@ -2686,20 +2686,21 @@
>  
>  	 */
>  
> -	now = warning_time = jiffies;
> +	notify_time = jiffies + 1*HZ;
> +	warning_time = jiffies + 10*HZ;
>  	while (atomic_read(&dev->refcnt) != 1) {
> -		if ((jiffies - now) > 1*HZ) {
> +		if (time_after(jiffies, notify_time)) {
>  			/* Rebroadcast unregister notification */
>  			notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev);
>  		}
>  		current->state = TASK_INTERRUPTIBLE;
>  		schedule_timeout(HZ/4);
>  		current->state = TASK_RUNNING;
> -		if ((jiffies - warning_time) > 10*HZ) {
> -			printk(KERN_EMERG "unregister_netdevice: waiting for %s to "
> -					"become free. Usage count = %d\n",
> +		if (time_after(jiffies, warning_time)) {
> +			printk(KERN_EMERG "unregister_netdevice: waiting for %s"
> +					" to become free. Usage count = %d\n",
>  					dev->name, atomic_read(&dev->refcnt));
> -			warning_time = jiffies;
> +			warning_time = jiffies + 10*HZ;
>  		}
>  	}
>  	dev_put(dev);
> --
> Andreas Dilger

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-11-05 19:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-03 23:29 [PATCH] net/core/dev.c jiffies cleanup Andreas Dilger
2001-11-05 16:55 ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).