From: Ben Gras Date: Fri, 12 Jan 2007 13:33:12 +0000 (+0000) Subject: use servers/inet/mq.[ch] to queue messages using mq_queue() in X-Git-Tag: v3.1.3~118 X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=b01aff70d26031dc5f7b6874be8c38379cdf3f80;p=minix.git use servers/inet/mq.[ch] to queue messages using mq_queue() in libdriver. at_wini now queues messages it can't handle it receives when waiting for an interrupt. this way it can do receive(ANY) and timeouts should be working again (were broken for VFS, as with the advent of VFS, at_wini could get requests from a filesystem while it was waiting for an interrupt - as a hack, the receive() was changed to receive(HARDWARE)). Added mq.c to libdriver, and made libdriver an actual library that drivers link with -L../libdriver -ldriver. (So adding files, if necessary, is easier next time.) --- diff --git a/drivers/at_wini/Makefile b/drivers/at_wini/Makefile index 25c17e7a7..9f76b906a 100644 --- a/drivers/at_wini/Makefile +++ b/drivers/at_wini/Makefile @@ -14,22 +14,18 @@ p = ../libpci MAKE = exec make CC = exec cc CFLAGS = -I$i $(CPROFILE) -LDFLAGS = -i -LIBS = -lsysutil -lsys -ltimers +LDFLAGS = -i -L../libdriver +LIBS = -lsysutil -lsys -ltimers -ldriver OBJ = at_wini.o -LIBDRIVER = $d/libdriver/driver.o $d/libdriver/drvlib.o # build local binary all build: $(DRIVER) -$(DRIVER): $(OBJ) $(LIBDRIVER) - $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS) +$(DRIVER): $(OBJ) + $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS) install -S 32k $(DRIVER) -$(LIBDRIVER): - cd $d/libdriver && $(MAKE) - # install with other drivers install: /sbin/$(DRIVER) /sbin/$(DRIVER): $(DRIVER) diff --git a/drivers/at_wini/at_wini.c b/drivers/at_wini/at_wini.c index b7ed00cbc..f88805d1a 100644 --- a/drivers/at_wini/at_wini.c +++ b/drivers/at_wini/at_wini.c @@ -1925,28 +1925,36 @@ PRIVATE void w_intr_wait() message m; if (w_wn->irq != NO_IRQ) { - /* Wait for an interrupt that sets w_status to "not busy". */ + /* Wait for an interrupt that sets w_status to "not busy". + * (w_timeout() also clears w_status.) + */ while (w_wn->w_status & (STATUS_ADMBSY|STATUS_BSY)) { int rr; - if((rr=receive(HARDWARE, &m)) != OK) { /* expect HARD_INT message */ - printf("w_intr_wait: receive from ANY failed (%d)\n", - r); - continue; /* try again */ + if((rr=receive(ANY, &m)) != OK) + panic("at_wini", "receive(ANY) failed", rr); + switch(m.m_type) { + case SYN_ALARM: + /* Timeout. */ + w_timeout(); /* a.o. set w_status */ + break; + case HARD_INT: + /* Interrupt. */ + r= sys_inb(w_wn->base_cmd + REG_STATUS, &w_status); + if (r != 0) + panic("at_wini", "sys_inb failed", r); + w_wn->w_status= w_status; + ack_irqs(m.NOTIFY_ARG); + break; + case DEV_PING: + /* RS monitor ping. */ + notify(m.m_source); + break; + default: + /* unhandled message. + * queue it and handle it in the libdriver loop. + */ + mq_queue(&m); } - if (m.m_type == SYN_ALARM) { /* but check for timeout */ - w_timeout(); /* a.o. set w_status */ - } else if (m.m_type == HARD_INT) { - r= sys_inb(w_wn->base_cmd + REG_STATUS, &w_status); - if (r != 0) - panic("at_wini", "sys_inb failed", r); - w_wn->w_status= w_status; - ack_irqs(m.NOTIFY_ARG); - } else if (m.m_type == DEV_PING) { - notify(m.m_source); - } else { - printf("AT_WINI got unexpected message %d from %d\n", - m.m_type, m.m_source); - } } } else { /* Interrupt not yet allocated; use polling. */ @@ -2563,4 +2571,6 @@ PRIVATE int atapi_intr_wait() wn->w_status |= STATUS_ADMBSY; /* Assume not done yet. */ return(r); } + #endif /* ENABLE_ATAPI */ + diff --git a/drivers/bios_wini/Makefile b/drivers/bios_wini/Makefile index 56f193bc2..42ff49149 100644 --- a/drivers/bios_wini/Makefile +++ b/drivers/bios_wini/Makefile @@ -13,22 +13,17 @@ d = .. MAKE = exec make CC = exec cc CFLAGS = -I$i $(CPROFILE) -LDFLAGS = -i -LIBS = -lsysutil -lsys -ltimers +LDFLAGS = -i -L../libdriver +LIBS = -lsysutil -lsys -ltimers -ldriver OBJ = bios_wini.o -LIBDRIVER = $d/libdriver/driver.o $d/libdriver/drvlib.o - # build local binary all build: $(DRIVER) -$(DRIVER): $(OBJ) $(LIBDRIVER) - $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS) +$(DRIVER): $(OBJ) + $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS) install -S 8k $(DRIVER) -$(LIBDRIVER): - cd $d/libdriver && $(MAKE) - # install with other drivers install: /sbin/$(DRIVER) /sbin/$(DRIVER): $(DRIVER) diff --git a/drivers/cmos/Makefile b/drivers/cmos/Makefile index 5366c41b5..8be22f40b 100644 --- a/drivers/cmos/Makefile +++ b/drivers/cmos/Makefile @@ -13,23 +13,17 @@ d = .. MAKE = exec make CC = exec cc CFLAGS = -I$i $(CPROFILE) -LDFLAGS = -i -LIBS = -lsysutil -lsys +LDFLAGS = -i -L../libdriver +LIBS = -lsysutil -lsys -ldriver OBJ = cmos.o -LIBDRIVER = $d/libdriver/driver.o - # build local binary all build: $(DRIVER) -$(DRIVER): $(OBJ) $(LIBDRIVER) - $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS) +$(DRIVER): $(OBJ) + $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS) install -S 8k $(DRIVER) -$(LIBDRIVER): - cd $d/libdriver && $(MAKE) - - # install with other drivers install: /sbin/$(DRIVER) /sbin/$(DRIVER): $(DRIVER) diff --git a/drivers/floppy/Makefile b/drivers/floppy/Makefile index db9bd0bd3..5be367445 100644 --- a/drivers/floppy/Makefile +++ b/drivers/floppy/Makefile @@ -13,21 +13,17 @@ d = .. MAKE = exec make CC = exec cc CFLAGS = -I$i $(CPROFILE) -LDFLAGS = -i -LIBS = -lsysutil -lsys -ltimers +LDFLAGS = -i -L../libdriver +LIBS = -lsysutil -ldriver -lsys -ltimers OBJ = floppy.o -LIBDRIVER = $d/libdriver/driver.o $d/libdriver/drvlib.o # build local binary all build: $(DRIVER) -$(DRIVER): $(OBJ) $(LIBDRIVER) - $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS) +$(DRIVER): $(OBJ) + $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS) install -S 8k $(DRIVER) -$(LIBDRIVER): - cd $d/libdriver && $(MAKE) - # install with other drivers install: /sbin/$(DRIVER) /sbin/$(DRIVER): $(DRIVER) diff --git a/drivers/libdriver/Makefile b/drivers/libdriver/Makefile index 93bb1d740..5407bfdf1 100644 --- a/drivers/libdriver/Makefile +++ b/drivers/libdriver/Makefile @@ -12,15 +12,19 @@ CC = exec cc CFLAGS = -I$i $(CPROFILE) LDFLAGS = -i LIBS = -lsysutil -lsys +LIB = libdriver.a -OBJECTS = driver.o drvlib.o +OBJECTS = driver.o drvlib.o mq.o -all build install: $(OBJECTS) +all build install: $(LIB) + +$(LIB): $(OBJECTS) + ar rc $(LIB) $(OBJECTS) # $(CC) -c $@ $(LDFLAGS) $(OBJ) $(LIBS) clean: - rm -f *.o *.bak + rm -f *.o *.bak *.a depend: /usr/bin/mkdep "$(CC) -E $(CPPFLAGS)" *.c > .depend diff --git a/drivers/libdriver/driver.c b/drivers/libdriver/driver.c index 58e7f5929..4f7302331 100644 --- a/drivers/libdriver/driver.c +++ b/drivers/libdriver/driver.c @@ -39,6 +39,7 @@ #include "../drivers.h" #include +#include #include "driver.h" #if (CHIP == INTEL) @@ -68,6 +69,7 @@ FORWARD _PROTOTYPE( int do_rdwt, (struct driver *dr, message *mp, int safe) ); FORWARD _PROTOTYPE( int do_vrdwt, (struct driver *dr, message *mp, int safe) ); int device_caller; +PRIVATE mq_t *queue_head = NULL; /*===========================================================================* * driver_task * @@ -80,6 +82,9 @@ struct driver *dp; /* Device dependent entry points. */ int r, proc_nr; message mess; + /* Init MQ library. */ + mq_init(); + /* Get a DMA buffer. */ init_buffer(); @@ -87,9 +92,19 @@ struct driver *dp; /* Device dependent entry points. */ * it out, and sends a reply. */ while (TRUE) { - - /* Wait for a request to read or write a disk block. */ - if (receive(ANY, &mess) != OK) continue; + /* Any queued messages? Oldest are at the head. */ + if(queue_head) { + mq_t *mq; + mq = queue_head; + memcpy(&mess, &mq->mq_mess, sizeof(mess)); + queue_head = queue_head->mq_next; + mq_free(mq); + } else { + int s; + /* Wait for a request to read or write a disk block. */ + if ((s=receive(ANY, &mess)) != OK) + panic((*dp->dr_name)(),"receive() failed", s); + } device_caller = mess.m_source; proc_nr = mess.IO_ENDPT; @@ -427,3 +442,26 @@ int safe; /* addresses or grants? */ } return(OK); } + +/*===========================================================================* + * mq_queue * + *===========================================================================*/ +PUBLIC int mq_queue(message *m) +{ + mq_t *mq, *mi; + + if(!(mq = mq_get())) + panic("libdriver","mq_queue: mq_get failed", NO_NUM); + memcpy(&mq->mq_mess, m, sizeof(mq->mq_mess)); + mq->mq_next = NULL; + if(!queue_head) { + queue_head = mq; + } else { + for(mi = queue_head; mi->mq_next; mi = mi->mq_next) + ; + mi->mq_next = mq; + } + + return OK; +} + diff --git a/drivers/libdriver/driver.h b/drivers/libdriver/driver.h index 1d71672ab..8c019e92e 100644 --- a/drivers/libdriver/driver.h +++ b/drivers/libdriver/driver.h @@ -74,6 +74,7 @@ _PROTOTYPE( int nop_cancel, (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int nop_select, (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int do_diocntl, (struct driver *dp, message *m_ptr, int safe) ); _PROTOTYPE( int nop_ioctl, (struct driver *dp, message *m_ptr, int safe) ); +_PROTOTYPE( int mq_queue, (message *m_ptr) ); /* Parameters for the disk drive. */ #define SECTOR_SIZE 512 /* physical sector size in bytes */ diff --git a/drivers/libdriver/mq.c b/drivers/libdriver/mq.c new file mode 100644 index 000000000..a80900d83 --- /dev/null +++ b/drivers/libdriver/mq.c @@ -0,0 +1,61 @@ +/* +inet/mq.c + +Created: Jan 3, 1992 by Philip Homburg + +Copyright 1995 Philip Homburg +*/ + +#include +#include + +#include +#include +#include +#include +#include + +#define MQ_SIZE 128 + +PRIVATE mq_t mq_list[MQ_SIZE]; +PRIVATE mq_t *mq_freelist; + +void mq_init() +{ + int i; + + mq_freelist= NULL; + for (i= 0; imq_next; + mq->mq_next= NULL; + assert(mq->mq_allocated == 0); + mq->mq_allocated= 1; + return mq; +} + +void mq_free(mq) +mq_t *mq; +{ + mq->mq_next= mq_freelist; + mq_freelist= mq; + assert(mq->mq_allocated == 1); + mq->mq_allocated= 0; +} + +/* + * $PchId: mq.c,v 1.7 1998/10/23 20:10:47 philip Exp $ + */ diff --git a/drivers/log/Makefile b/drivers/log/Makefile index 06f2f7d56..af51f725d 100644 --- a/drivers/log/Makefile +++ b/drivers/log/Makefile @@ -12,22 +12,17 @@ d = .. MAKE = exec make CC = exec cc CFLAGS = -I$i $(CPROFILE) -LDFLAGS = -i -LIBS = -lsysutil -lsys +LDFLAGS = -i -L../libdriver +LIBS = -lsysutil -ldriver -lsys OBJ = log.o diag.o kputc.o -LIBDRIVER = $d/libdriver/driver.o - # build local binary all build: $(DRIVER) -$(DRIVER): $(OBJ) $(LIBDRIVER) - $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS) +$(DRIVER): $(OBJ) + $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS) install -S 16kb $(DRIVER) -$(LIBDRIVER): - cd $d/libdriver && $(MAKE) - # install with other drivers install: $(DRIVER) install -o root -cs $? /sbin/$(DRIVER) diff --git a/drivers/memory/Makefile b/drivers/memory/Makefile index fa7b2d124..2db1efbb3 100644 --- a/drivers/memory/Makefile +++ b/drivers/memory/Makefile @@ -13,8 +13,8 @@ d = .. MAKE = exec make CC = exec cc CFLAGS = -I$i -LDFLAGS = -i -LIBS = -lsysutil -lsys +LDFLAGS = -i -L../libdriver +LIBS = -lsysutil -ldriver -lsys # imgrd_s.s is the ACK assembler version of the ramdisk. For more portability, # use the C version imgrd.c. However, the C compiler takes too much memory @@ -23,14 +23,12 @@ IMGRD=imgrd_s.o #IMGRD=imgrd.c OBJ = memory.o allocmem.o $(IMGRD) -LIBDRIVER = $d/libdriver/driver.o - # build local binary all build: $(DRIVER) -$(DRIVER): ramdisk_image $(OBJ) $(LIBDRIVER) - $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS) +$(DRIVER): ramdisk_image $(OBJ) + $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS) install -S 8k $(DRIVER) imgrd.o: ramdisk/image.c @@ -38,9 +36,6 @@ imgrd.o: ramdisk/image.c imgrd_s.o: ramdisk/image.s TMPDIR=/usr/tmp $(CC) -T /usr/tmp -c imgrd_s.s -$(LIBDRIVER): - cd $d/libdriver && $(MAKE) - ramdisk_image: cd ramdisk && make diff --git a/drivers/random/Makefile b/drivers/random/Makefile index b535ceea8..547abb38e 100644 --- a/drivers/random/Makefile +++ b/drivers/random/Makefile @@ -13,22 +13,17 @@ d = .. MAKE = exec make CC = exec cc CFLAGS = -I$i $(CPROFILE) -LDFLAGS = -i -LIBS = -lsysutil -lsys +LDFLAGS = -i -L../libdriver +LIBS = -lsysutil -ldriver -lsys OBJ = main.o random.o sha2.o aes/rijndael_api.o aes/rijndael_alg.o -LIBDRIVER = $d/libdriver/driver.o - # build local binary all build: $(DRIVER) -$(DRIVER): $(OBJ) $(LIBDRIVER) - $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS) +$(DRIVER): $(OBJ) + $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS) install -S 8k $(DRIVER) -$(LIBDRIVER): - cd $d/libdriver && $(MAKE) - aes/rijndael_api.o: $(CC) -c -o $@ aes/rijndael_api.c diff --git a/include/minix/mq.h b/include/minix/mq.h new file mode 100644 index 000000000..28423688b --- /dev/null +++ b/include/minix/mq.h @@ -0,0 +1,27 @@ +/* +inet/mq.h + +Created: Jan 3, 1992 by Philip Homburg + +Copyright 1995 Philip Homburg +*/ + +#ifndef INET__MQ_H +#define INET__MQ_H + +typedef struct mq +{ + message mq_mess; + struct mq *mq_next; + int mq_allocated; +} mq_t; + +_PROTOTYPE( mq_t *mq_get, (void) ); +_PROTOTYPE( void mq_free, (mq_t *mq) ); +_PROTOTYPE( void mq_init, (void) ); + +#endif /* INET__MQ_H */ + +/* + * $PchId: mq.h,v 1.4 1995/11/21 06:40:30 philip Exp $ + */