Linux PARISC architecture development
 help / color / mirror / Atom feed
* [parisc-linux] J5000 LED LCD patch (take 2)
@ 2005-03-24 18:48 David Pye
  2005-03-24 20:01 ` [parisc-linux] A second LCD patch David Pye
  2005-03-24 20:05 ` [parisc-linux] J5000 LED LCD patch (take 2) James Bottomley
  0 siblings, 2 replies; 16+ messages in thread
From: David Pye @ 2005-03-24 18:48 UTC (permalink / raw)
  To: parisc-linux


[-- Attachment #1.1.1: Type: text/plain, Size: 1058 bytes --]

Hi,

Attached is the latest iteration of my patch, with the feedback from Grant 
Grundler incorporated (hopefully!)

The other changes are:

Adjust the scheduling so the work queue item runs only every 5 jiffies, 
instead of each one (as per the original tasklet). This means we can do a 
couple more calculations, and still hopefully be ahead in the efficiency 
stakes.

Set and enforce a minimum on-time for LEDs - this prevents the LCD ones 
'ghosting' under rapid LAN/IO on/off. This also applies to LED systems too. 
The minimum on-time is currently 100mS - feedback welcome as to whether this 
should be made LCD-only, or adjusted up/downwards. (This is necessary because 
once the min_cmd_delay has been taken into effect, rapidly fluttering LAN/IO 
lcd symbols cause the heartbeat to stutter slightly).

On my J5000, this gives a perfectly uniform heartbeat regardless of lan/io 
activity, and also prevents the lan/io symbols ghosting during continuous 
traffic.

As before, comments/suggestions welcome!

Cheers,

David

[-- Attachment #1.1.2: led_lcd_patch --]
[-- Type: text/x-diff, Size: 12928 bytes --]

diff -urpN linux-2.6.12-rc1-pa2/arch/parisc/kernel/time.c worktree/arch/parisc/kernel/time.c
--- linux-2.6.12-rc1-pa2/arch/parisc/kernel/time.c	2004-10-21 19:58:24.000000000 +0100
+++ worktree/arch/parisc/kernel/time.c	2005-03-24 01:04:32.000000000 +0000
@@ -89,14 +89,6 @@ irqreturn_t timer_interrupt(int irq, voi
 		}
 	}
     
-#ifdef CONFIG_CHASSIS_LCD_LED
-	/* Only schedule the led tasklet on cpu 0, and only if it
-	 * is enabled.
-	 */
-	if (cpu == 0 && !atomic_read(&led_tasklet.count))
-		tasklet_schedule(&led_tasklet);
-#endif
-
 	/* check soft power switch status */
 	if (cpu == 0 && !atomic_read(&power_tasklet.count))
 		tasklet_schedule(&power_tasklet);
diff -urpN linux-2.6.12-rc1-pa2/drivers/parisc/led.c worktree/drivers/parisc/led.c
--- linux-2.6.12-rc1-pa2/drivers/parisc/led.c	2005-03-18 13:17:10.000000000 +0000
+++ worktree/drivers/parisc/led.c	2005-03-24 01:07:08.000000000 +0000
@@ -18,6 +18,9 @@
  * Changes:
  *      - Audit copy_from_user in led_proc_write.
  *                                Daniele Bellucci <bellucda@tiscali.it>
+ *	- Switch from using a tasklet to a work queue, so the led_LCD_driver
+ *	  	can sleep.
+ *	  			  David Pye <dmp@davidmpye.dyndns.org>
  */
 
 #include <linux/config.h>
@@ -37,6 +40,7 @@
 #include <linux/proc_fs.h>
 #include <linux/ctype.h>
 #include <linux/blkdev.h>
+#include <linux/workqueue.h>
 #include <asm/io.h>
 #include <asm/processor.h>
 #include <asm/hardware.h>
@@ -46,9 +50,9 @@
 #include <asm/uaccess.h>
 
 /* The control of the LEDs and LCDs on PARISC-machines have to be done 
-   completely in software. The necessary calculations are done in a tasklet
-   which is scheduled at every timer interrupt and since the calculations 
-   may consume relatively much CPU-time some of the calculations can be 
+   completely in software. The necessary calculations are done in a work queue
+   task which is scheduled regularly, and since the calculations may consume a 
+   relatively large amount of CPU time, some of the calculations can be 
    turned off with the following variables (controlled via procfs) */
 
 static int led_type = -1;
@@ -58,13 +62,16 @@ static int led_lanrxtx = 1;
 static char lcd_text[32];
 static char lcd_text_default[32];
 
+static struct workqueue_struct *led_wq;
+static void led_work_func(void *);
+static DECLARE_WORK(led_task, led_work_func, NULL);
+
 #if 0
 #define DPRINTK(x)	printk x
 #else
 #define DPRINTK(x)
 #endif
 
-
 struct lcd_block {
 	unsigned char command;	/* stores the command byte      */
 	unsigned char on;	/* value for turning LED on     */
@@ -115,12 +122,24 @@ lcd_info __attribute__((aligned(8))) =
 #define LCD_DATA_REG	lcd_info.lcd_data_reg_addr	 
 #define LED_DATA_REG	lcd_info.lcd_cmd_reg_addr	/* LASI & ASP only */
 
+#define LED_HASLCD 1
+#define LED_NOLCD  0
+
+/* The workqueue must be created at init-time */
+static int start_task(void) 
+{	
+	/* Create the work queue and queue the LED task */
+	led_wq = create_singlethread_workqueue("led_wq");	
+	queue_work(led_wq, &led_task);
+
+	return 0;
+}
+
+device_initcall(start_task);
 
 /* ptr to LCD/LED-specific function */
 static void (*led_func_ptr) (unsigned char);
 
-#define LED_HASLCD 1
-#define LED_NOLCD  0
 #ifdef CONFIG_PROC_FS
 static int led_proc_read(char *page, char **start, off_t off, int count, 
 	int *eof, void *data)
@@ -285,53 +304,41 @@ static void led_LASI_driver(unsigned cha
 /*
    ** 
    ** led_LCD_driver()
-   ** 
-   ** The logic of the LCD driver is, that we write at every scheduled call
-   ** only to one of LCD_CMD_REG _or_ LCD_DATA_REG - registers.
-   ** That way we don't need to let this tasklet busywait for min_cmd_delay
-   ** milliseconds.
-   **
-   ** TODO: check the value of "min_cmd_delay" against the value of HZ.
    **   
  */
 static void led_LCD_driver(unsigned char leds)
 {
-	static int last_index;	/* 0:heartbeat, 1:disk, 2:lan_in, 3:lan_out */
-	static int last_was_cmd;/* 0: CMD was written last, 1: DATA was last */
-	struct lcd_block *block_ptr;
-	int value;
-
-	switch (last_index) {
-	    case 0:	block_ptr = &lcd_info.heartbeat;
-			value = leds & LED_HEARTBEAT;
-			break;
-	    case 1:	block_ptr = &lcd_info.disk_io;
-			value = leds & LED_DISK_IO;
-			break;					
-	    case 2:	block_ptr = &lcd_info.lan_rcv;
-			value = leds & LED_LAN_RCV;
-			break;					
-	    case 3:	block_ptr = &lcd_info.lan_tx;
-			value = leds & LED_LAN_TX;
-			break;
-	    default:	/* should never happen: */
-			return;
-	}
+	static int lastleds, i;
+	static unsigned char mask[4] = { LED_HEARTBEAT, LED_DISK_IO,
+		LED_LAN_RCV, LED_LAN_TX };
+	
+	static struct lcd_block * blockp[4] = {
+		&lcd_info.heartbeat,
+		&lcd_info.disk_io,
+		&lcd_info.lan_rcv,
+		&lcd_info.lan_tx
+	};
 
-	if (last_was_cmd) {
-	    /* write the value to the LCD data port */
-    	    gsc_writeb( value ? block_ptr->on : block_ptr->off, LCD_DATA_REG );
-	} else {
-	    /* write the command-byte to the LCD command register */
-    	    gsc_writeb( block_ptr->command, LCD_CMD_REG );
-	}    
-	
-	/* now update the vars for the next interrupt iteration */ 
-	if (++last_was_cmd == 2) { /* switch between cmd & data */
-	    last_was_cmd = 0;
-	    if (++last_index == 4) 
-		last_index = 0;	 /* switch back to heartbeat index */
+	/* Convert min_cmd_delay (uS) to jiffies */
+	unsigned long wait_jiffies = 1 + (lcd_info.min_cmd_delay * HZ) / 1000000;
+
+	for (i=0; i<4; ++i) 
+	{
+		if ((leds & mask[i]) != (lastleds & mask[i])) 
+		{
+			gsc_writeb( blockp[i]->command, LCD_CMD_REG );
+			
+			set_current_state(TASK_UNINTERRUPTIBLE);		
+			schedule_timeout(wait_jiffies);	
+
+			gsc_writeb( leds & mask[i] ? blockp[i]->on : 
+					blockp[i]->off, LCD_DATA_REG );
+			
+			set_current_state(TASK_UNINTERRUPTIBLE);		
+			schedule_timeout(wait_jiffies);	
+		}
 	}
+	lastleds = leds;
 }
 
 
@@ -355,7 +362,7 @@ static __inline__ int led_get_net_activi
 
 	rx_total = tx_total = 0;
 	
-	/* we are running as tasklet, so locking dev_base 
+	/* we are running as a workqueue task, so locking dev_base 
 	 * for reading should be OK */
 	read_lock(&dev_base_lock);
 	for (dev = dev_base; dev; dev = dev->next) {
@@ -417,10 +424,9 @@ static __inline__ int led_get_diskio_act
 
 
 /*
-   ** led_tasklet_func()
+   ** led_work_func()
    ** 
-   ** is scheduled at every timer interrupt from time.c and
-   ** updates the chassis LCD/LED 
+   ** is scheduled every 5 jiffies and updates the chassis LCD/LED 
 
     TODO:
     - display load average (older machines like 715/64 have 4 "free" LED's for that)
@@ -431,66 +437,102 @@ static __inline__ int led_get_diskio_act
 #define HEARTBEAT_2ND_RANGE_START (HZ*22/100)
 #define HEARTBEAT_2ND_RANGE_END   (HEARTBEAT_2ND_RANGE_START + HEARTBEAT_LEN)
 
-#define NORMALIZED_COUNT(count) (count/(HZ/100))
+#define LED_MINIMUM_ON_TIME (HZ*10/100)
 
-static void led_tasklet_func(unsigned long unused)
+static void led_work_func (void *unused)
 {
 	static unsigned char lastleds;
-	unsigned char currentleds; /* stores current value of the LEDs */
-	static unsigned long count; /* static incremented value, not wrapped */
 	static unsigned long count_HZ; /* counter in range 0..HZ */
 
+	static unsigned long diskio_on_jiffies;
+	static unsigned long lantx_on_jiffies;
+	static unsigned long lanrcv_on_jiffies;
+
+	unsigned char currentleds = 0; /* stores current value of the LEDs */
+	
 	/* exit if not initialized */
 	if (!led_func_ptr)
 	    return;
 
-	/* increment the local counters */
-	++count;
-	if (++count_HZ == HZ)
+	/* increment the local counter */
+	count_HZ += 5;
+	if (count_HZ == HZ)
 	    count_HZ = 0;
 
-	currentleds = lastleds;
-
 	if (led_heartbeat)
 	{
 		/* flash heartbeat-LED like a real heart (2 x short then a long delay) */
 		if (count_HZ<HEARTBEAT_LEN || 
 		    (count_HZ>=HEARTBEAT_2ND_RANGE_START && count_HZ<HEARTBEAT_2ND_RANGE_END)) 
 		    currentleds |= LED_HEARTBEAT;
-		else
-		    currentleds &= ~LED_HEARTBEAT;
 	}
 
-	/* look for network activity and flash LEDs respectively */
-	if (led_lanrxtx && ((NORMALIZED_COUNT(count)+(8/2)) & 7) == 0)
+	/* If the leds are on, but should be turned off, make sure they have been on for
+	 * the minimum time, to prevent 'flutter' 
+	 */
+
+	/* look for network activity and flash LEDs accordingly */
+	if (led_lanrxtx)
 	{
-		currentleds &= ~(LED_LAN_RCV | LED_LAN_TX);
-		currentleds |= led_get_net_activity();
+		unsigned char new_lan_leds = led_get_net_activity();
+	
+		/* TX LED */
+		if (new_lan_leds & LED_LAN_TX) 
+		{
+			currentleds |= LED_LAN_TX;
+			lantx_on_jiffies = jiffies;
+		}
+		else if (lastleds & LED_LAN_TX && time_before(jiffies, lantx_on_jiffies + LED_MINIMUM_ON_TIME))
+		{
+			currentleds |= LED_LAN_TX;
+		}
+		
+		/* RCV LED */
+
+		if (new_lan_leds & LED_LAN_RCV) 
+		{
+			currentleds |= LED_LAN_RCV;
+			lanrcv_on_jiffies = jiffies;
+		}
+		else if (lastleds & LED_LAN_RCV && time_before(jiffies, lanrcv_on_jiffies + LED_MINIMUM_ON_TIME)) 
+		{
+			currentleds |= LED_LAN_RCV;
+		}
 	}
 
-	/* avoid to calculate diskio-stats at same irq  as netio-stats */
-	if (led_diskio && (NORMALIZED_COUNT(count) & 7) == 0)
+	/* Calculate disk IO */
+	if (led_diskio)
 	{
-		currentleds &= ~LED_DISK_IO;
-		currentleds |= led_get_diskio_activity();
+		unsigned char new_io_led = led_get_diskio_activity();
+		
+		if (new_io_led & LED_DISK_IO) 
+		{
+			currentleds |= LED_DISK_IO;
+			diskio_on_jiffies = jiffies;
+		}
+		else if (lastleds & LED_DISK_IO && time_before(jiffies, diskio_on_jiffies + LED_MINIMUM_ON_TIME)) 
+		{
+			currentleds |= LED_DISK_IO;
+		}
 	}
 
 	/* blink all LEDs twice a second if we got an Oops (HPMC) */
-	if (oops_in_progress) {
+	if (oops_in_progress) 
+	{
 		currentleds = (count_HZ<=(HZ/2)) ? 0 : 0xff;
 	}
 	
 	/* update the LCD/LEDs */
-	if (currentleds != lastleds) {
-	    led_func_ptr(currentleds);
-	    lastleds = currentleds;
+	if (currentleds != lastleds)
+	{
+		led_func_ptr(currentleds);
+		lastleds = currentleds;
 	}
+	
+	/* Requeue ourself to run in 5 jiffies */	
+	queue_delayed_work(led_wq, &led_task, 5);
 }
 
-/* main led tasklet struct (scheduled from time.c) */
-DECLARE_TASKLET_DISABLED(led_tasklet, led_tasklet_func, 0);
-
-
 /*
    ** led_halt()
    ** 
@@ -519,9 +561,13 @@ static int led_halt(struct notifier_bloc
 	default:		return NOTIFY_DONE;
 	}
 	
-	/* completely stop the LED/LCD tasklet */
-	tasklet_disable(&led_tasklet);
-
+	/* Cancel the work item and delete the queue */
+	if (led_wq) {
+		if (cancel_delayed_work(&led_task) == 0) 
+			flush_workqueue(led_wq);
+		destroy_workqueue(led_wq);
+	}
+ 
 	if (lcd_info.model == DISPLAY_MODEL_LCD)
 		lcd_print(txt);
 	else
@@ -586,9 +632,6 @@ int __init register_led_driver(int model
 	initialized++;
 	register_reboot_notifier(&led_notifier);
 
-	/* start the led tasklet for the first time */
-	tasklet_enable(&led_tasklet);
-	
 	return 0;
 }
 
@@ -623,7 +666,7 @@ void __init register_led_regions(void)
    ** lcd_print()
    ** 
    ** Displays the given string on the LCD-Display of newer machines.
-   ** lcd_print() disables the timer-based led tasklet during its 
+   ** lcd_print() disables the timer-based led work task during its 
    ** execution and enables it afterwards again.
    **
  */
@@ -634,8 +677,13 @@ int lcd_print( char *str )
 	if (!led_func_ptr || lcd_info.model != DISPLAY_MODEL_LCD)
 	    return 0;
 	
-	/* temporarily disable the led tasklet */
-	tasklet_disable(&led_tasklet);
+	/* temporarily disable the led work task */
+	if (led_wq) {
+		if (cancel_delayed_work(&led_task) == 0) 
+			flush_workqueue(led_wq);
+	}
+ 	/* copy display string to buffer for procfs */
+ 	strlcpy(lcd_text, str, sizeof(lcd_text));
 
 	/* copy display string to buffer for procfs */
 	strlcpy(lcd_text, str, sizeof(lcd_text));
@@ -653,8 +701,10 @@ int lcd_print( char *str )
 	    udelay(lcd_info.min_cmd_delay);
 	}
 	
-	/* re-enable the led tasklet */
-	tasklet_enable(&led_tasklet);
+	/* re-queue the work */
+	if (led_wq) {
+		queue_work(led_wq, &led_task);
+	}
 
 	return lcd_info.lcd_width;
 }
diff -urpN linux-2.6.12-rc1-pa2/include/asm-parisc/led.h worktree/include/asm-parisc/led.h
--- linux-2.6.12-rc1-pa2/include/asm-parisc/led.h	2004-12-30 08:07:48.000000000 +0000
+++ worktree/include/asm-parisc/led.h	2005-03-24 01:04:54.000000000 +0000
@@ -23,9 +23,6 @@
 
 #define LED_CMD_REG_NONE 0		/* NULL == no addr for the cmd register */
 
-/* led tasklet struct */
-extern struct tasklet_struct led_tasklet;
-
 /* register_led_driver() */
 int __init register_led_driver(int model, unsigned long cmd_reg, unsigned long data_reg);
 

[-- Attachment #1.2: Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 169 bytes --]

_______________________________________________
parisc-linux mailing list
parisc-linux@lists.parisc-linux.org
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux

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

end of thread, other threads:[~2005-03-28  2:13 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-24 18:48 [parisc-linux] J5000 LED LCD patch (take 2) David Pye
2005-03-24 20:01 ` [parisc-linux] A second LCD patch David Pye
2005-03-24 20:05 ` [parisc-linux] J5000 LED LCD patch (take 2) James Bottomley
2005-03-24 21:00   ` David Pye
2005-03-25  6:25     ` Grant Grundler
2005-03-25 17:05       ` David Pye
2005-03-25 21:50         ` David Pye
2005-03-26  7:13           ` Grant Grundler
2005-03-26 15:14             ` David Pye
2005-03-26 15:33               ` James Bottomley
     [not found]                 ` <200503261545.05372.dmp@davidmpye.dyndns.org>
2005-03-26 15:51                   ` David Pye
2005-03-27  8:53               ` Grant Grundler
2005-03-27  9:38                 ` David Pye
2005-03-27 17:55                   ` David Pye
2005-03-28  1:51                     ` Grant Grundler
2005-03-28  2:13                   ` Grant Grundler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox