Subject: Re: wd.c patch to reduce kernel stack usage
To: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-kern
Date: 06/27/2002 13:23:16
On Thu, Jun 27, 2002 at 04:16:21AM +0900, YAMAMOTO Takashi wrote:

 > is attached patch ok?
 > (in order to reduce kernel stack usage.)

Another option would be to allocate the error reporting buffer in
the device's softc structure.

 > 
 > ---
 > YAMAMOTO Takashi<yamt@mwd.biglobe.ne.jp>

 > Index: wd.c
 > ===================================================================
 > RCS file: /cvs/cvsroot/syssrc/sys/dev/ata/wd.c,v
 > retrieving revision 1.220
 > diff -u -p -r1.220 wd.c
 > --- wd.c	2002/01/13 17:24:30	1.220
 > +++ wd.c	2002/06/26 16:12:40
 > @@ -130,6 +130,8 @@ extern int wdcdebug_wd_mask; /* init'ed 
 >  #define WDCDEBUG_PRINT(args, level)
 >  #endif
 >  
 > +#define	WD_MAX_ERROR_LEN	256
 > +
 >  struct wd_softc {
 >  	/* General disk infos */
 >  	struct device sc_dev;
 > @@ -589,14 +591,13 @@ wddone(v)
 >  {
 >  	struct wd_softc *wd = v;
 >  	struct buf *bp = wd->sc_bp;
 > -	char buf[256], *errbuf = buf;
 > +	char *buf = 0, *errbuf;
 >  	WDCDEBUG_PRINT(("wddone %s\n", wd->sc_dev.dv_xname),
 >  	    DEBUG_XFERS);
 >  
 >  	if (bp == NULL)
 >  		return;
 >  	bp->b_resid = wd->sc_wdc_bio.bcount;
 > -	errbuf[0] = '\0';
 >  	switch (wd->sc_wdc_bio.error) {
 >  	case ERR_DMA:
 >  		errbuf = "DMA error";
 > @@ -612,11 +613,19 @@ wddone(v)
 >  		if (wd->sc_wdc_bio.r_error != 0 &&
 >  		    (wd->sc_wdc_bio.r_error & ~(WDCE_MC | WDCE_MCR)) == 0)
 >  			goto noerror;
 > -		wdperror(wd->drvp, wd->sc_wdc_bio.r_error, errbuf);
 > +		buf = malloc(WD_MAX_ERROR_LEN, M_DEVBUF, M_NOWAIT);
 > +		if (buf) {
 > +			errbuf = buf;
 > +			wdperror(wd->drvp, wd->sc_wdc_bio.r_error, errbuf);
 > +		}
 > +		else
 > +			errbuf = ""; /* XXX */
 >  retry:		/* Just reset and retry. Can we do more ? */
 >  		wd->atabus->ata_reset_channel(wd->drvp);
 >  		diskerr(bp, "wd", errbuf, LOG_PRINTF,
 >  		    wd->sc_wdc_bio.blkdone, wd->sc_dk.dk_label);
 > +		if (buf)
 > +			free(buf, M_DEVBUF);
 >  		if (wd->retries++ < WDIORETRIES) {
 >  			printf(", retrying\n");
 >  			callout_reset(&wd->sc_restart_ch, RECOVERYTIME,


-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>