[PATCH 4 of 6]
Juan Perez-Sanchez <[email protected]>
| Newsgroups | org.kernel.vger.linux-8086 |
|---|---|
| Message-ID | <CAD6VGua5JoWzgm3gXGkV1aiug4=QN_Pdt243c-_6uBSb4axB_g@mail.gmail.com> |
Hi, In block driver doshd.c (the default driver), reading and writing sectors is now done directly from/to block buffers. Previously the sectors were copied to a buffer located at BUFSEG:0x0000 as an intermediate and unnecessary step. These changes were tested copying a lot of files running elks under qemu, checking the integrity of the copied files and running fsck for the modified filesystem under linux. Under the dioscuri emulator, with the ability to emulate the processor speed, obtained a reduction of 15 sec. in running time when copying the entire /bin directory from a total of 80 secs. 2. The modifications above, and other small changes to have a closer implementation with "directhd.c" also reduced the code size. 3. Small changes in fs/exec.c and kernel/sys.c to remove unused variables and redundant statements. 4. As result of the modifications the code size was reduced in 112 bytes. The Image builded without errors. The kernel was tested with QEMU and dioscuri emulators. Also in a PPro pc booting from floppy. Greetings, Juan
elksX.patch
(application/octet-stream, 8.4 KB)
diff -Nur elks.orig/arch/i86/drivers/block/doshd.c elks/arch/i86/drivers/block/doshd.c
--- elks.orig/arch/i86/drivers/block/doshd.c 2012-10-24 12:47:08.000000000 -0500
+++ elks/arch/i86/drivers/block/doshd.c 2013-02-23 11:55:28.000000000 -0600
@@ -41,6 +41,8 @@
#include <arch/segment.h>
#include <arch/system.h>
+#ifdef CONFIG_BLK_DEV_BIOS
+
#define MAJOR_NR BIOSHD_MAJOR
#define BIOSDISK
@@ -50,8 +52,6 @@
#define BUFSEG 0x800
-#ifdef CONFIG_BLK_DEV_BIOS
-
static int bioshd_ioctl(struct inode *, struct file *, unsigned int,
unsigned int);
@@ -59,31 +59,6 @@
static void bioshd_release(struct inode *, struct file *);
-/*@-type@*/
-
-static struct file_operations bioshd_fops = {
- NULL, /* lseek - default */
- block_read, /* read - general block-dev read */
- block_write, /* write - general block-dev write */
- NULL, /* readdir - bad */
- NULL, /* select */
- bioshd_ioctl, /* ioctl */
- bioshd_open, /* open */
- bioshd_release /* release */
-#ifdef BLOAT_FS
- ,
- NULL, /* fsync */
- NULL, /* check_media_change */
- NULL /* revalidate */
-#endif
-};
-
-/*@+type@*/
-
-static struct wait_queue dma_wait;
-
-static int dma_avail = 1;
-
static int bioshd_initialized = 0;
#if 0
@@ -102,14 +77,6 @@
int fdtype; /* matches fd_types or -1 if hd */
} drive_info[4];
-struct drive_infot fd_types[] = {
- {40, 9, 2, 0},
- {80, 15, 2, 1},
- {80, 9, 2, 2},
- {80, 18, 2, 3},
- {80, 36, 2, 4},
-};
-
/* This makes probing order more logical and
* avoids a few senseless seeks in some cases
*/
@@ -123,6 +90,20 @@
static int access_count[4] = { 0, 0, 0, 0 };
+static int bioshd_sizes[4 << 6] = { 0, };
+
+static struct wait_queue dma_wait;
+
+static int dma_avail = 1;
+
+struct drive_infot fd_types[] = {
+ {40, 9, 2, 0},
+ {80, 15, 2, 1},
+ {80, 9, 2, 2},
+ {80, 18, 2, 3},
+ {80, 36, 2, 4},
+};
+
static unsigned char hd_drive_map[4] = {
0x80, 0x81, /* hda, hdb */
0x00, 0x01 /* fd0, fd1 */
@@ -134,8 +115,6 @@
#endif
-static int bioshd_sizes[4 << 6] = { 0, };
-
static void bioshd_geninit(void);
static struct gendisk bioshd_gendisk = {
@@ -503,6 +482,23 @@
return 0;
}
+static struct file_operations bioshd_fops = {
+ NULL, /* lseek - default */
+ block_read, /* read - general block-dev read */
+ block_write, /* write - general block-dev write */
+ NULL, /* readdir - bad */
+ NULL, /* select */
+ bioshd_ioctl, /* ioctl */
+ bioshd_open, /* open */
+ bioshd_release /* release */
+#ifdef BLOAT_FS
+ ,
+ NULL, /* fsync */
+ NULL, /* check_media_change */
+ NULL /* revalidate */
+#endif
+};
+
#ifdef DOSHD_VERBOSE_DRIVES
#define TEMP_PRINT_DRIVES_MAX 4
#else
@@ -699,14 +695,12 @@
sleep_on(&dma_wait);
dma_avail = 0;
BD_IRQ = BIOSHD_INT;
- if (req->rq_cmd == WRITE) {
+ if (req->rq_cmd == WRITE)
BD_AX = (unsigned short int) (BIOSHD_WRITE | this_pass);
- fmemcpy(BUFSEG, 0, req->rq_seg, (__u16) buff,
- (this_pass * 512));
- } else
+ else
BD_AX = (unsigned short int) (BIOSHD_READ | this_pass);
- BD_BX = 0;
- BD_ES = BUFSEG;
+ BD_BX = (__u16) buff;
+ BD_ES = req->rq_seg;
BD_CX = (unsigned short int)
((cylinder << 8) | ((cylinder >> 2) & 0xc0) | sector);
BD_DX = (head << 8) | hd_drive_map[drive];
@@ -728,9 +722,6 @@
}
continue; /* try again */
}
- if (req->rq_cmd == READ)
- fmemcpy(req->rq_seg, (__u16) buff, BUFSEG, 0,
- (this_pass * 512));
/* In case it's already been freed */
if (!dma_avail) {
diff -Nur elks.orig/fs/exec.c elks/fs/exec.c
--- elks.orig/fs/exec.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/fs/exec.c 2013-02-23 11:55:28.000000000 -0600
@@ -59,8 +59,8 @@
struct inode *inode;
register struct file *filp = &file;
__registers *tregs;
- unsigned int suidfile, sgidfile, i;
- int retval, execformat;
+ unsigned int suidfile, sgidfile;
+ int retval;
__u16 ds = current->t_regs.ds;
seg_t cseg, dseg, stack_top = 0;
uid_t effuid;
@@ -87,7 +87,8 @@
* Build a reading file handle
*/
filp->f_mode = filp->f_count = 1;
- filp->f_pos = filp->f_flags = 0;
+ filp->f_flags = 0;
+ filp->f_pos = 0; /* FIXME - should call lseek */
filp->f_inode = inode;
#ifdef BLOAT_FS
@@ -108,7 +109,6 @@
*/
tregs = ¤t->t_regs;
tregs->ds = get_ds();
- filp->f_pos = 0; /* FIXME - should call lseek */
/*
* can I trust the following fields?
@@ -150,14 +150,14 @@
stack_top = msuph.msh_dbase;
if(stack_top & 0xf){
retval = -ENOEXEC;
- goto close_readexec;
+ goto close_readexec;
}
debug1("EXEC: New type executable stack = %x\n", stack_top);
}
#else
if((unsigned int) mh.hlen != 0x20){
retval = -ENOEXEC;
- goto close_readexec;
+ goto close_readexec;
}
#endif
@@ -169,15 +169,14 @@
cseg = 0;
{
- register char *pi = 0;
+ register struct task_struct *p = &task[0];
+
do {
- if ((task[(int)pi].state != TASK_UNUSED)
- && (task[(int)pi].t_inode == inode)) {
- cseg = mm_realloc(task[(int)pi].mm.cseg);
+ if ((p->state != TASK_UNUSED) && (p->t_inode == inode)) {
+ cseg = mm_realloc(p->mm.cseg);
break;
}
- ++pi;
- } while (((int)pi) < MAX_TASKS);
+ } while (++p < &task[MAX_TASKS]);
}
if (!cseg) {
@@ -190,7 +189,7 @@
}
/*
- * mh.chmem is "total size" requested by ld. Note that ld used to ask
+ * mh.chmem is "total size" requested by ld. Note that ld used to ask
* for (at least) 64K
*/
if (stack_top) {
@@ -229,7 +228,7 @@
goto close_readexec;
}
} else {
- filp->f_pos += mh.tseg;
+ filp->f_pos += mh.tseg;
}
tregs->ds = dseg;
@@ -243,7 +242,7 @@
mm_free(dseg);
goto close_readexec;
}
-
+
/*
* Wipe the BSS.
*/
@@ -257,7 +256,7 @@
: (char *) (len - slen);
count = slen;
fmemcpy(dseg, (__u16) ptr, current->mm.dseg, (__u16) sptr, (__u16) count);
-
+
/* argv and envp are two NULL-terminated arrays of pointers, located
* right after argc. This fixes them up so that the loaded program
* gets the right strings. */
@@ -338,7 +337,7 @@
currentp->euid = effuid;
if (sgidfile)
currentp->egid = effgid;
-
+
retval = 0;
wake_up(¤tp->p_parent->child_wait);
}
diff -Nur elks.orig/kernel/sys.c elks/kernel/sys.c
--- elks.orig/kernel/sys.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/kernel/sys.c 2013-02-23 12:03:25.000000000 -0600
@@ -50,20 +50,20 @@
}
if ((magic == 0x1D1E) && (magic_too == 0xC0DE)) {
- register int *pflag = &flag;
+ register int *pflag = (int *)flag;
- if (*pflag == 0x0123) {
+ if ((int)pflag == 0x0123) {
hard_reset_now();
}
- if (*pflag == 0x6789) {
+ if ((int)pflag == 0x6789) {
printk("System halted\n");
sys_kill(-1, SIGKILL);
do_exit(0);
}
- if ((*pflag == 0x4567) || !*pflag) {
- C_A_D = (*pflag ? 1 : 0);
+ if (((int)pflag == 0x4567) || !(int)pflag) {
+ C_A_D = ((int)pflag ? 1 : 0);
return 0;
}
}
@@ -88,7 +88,7 @@
#ifdef CONFIG_SYS_VERSION
/*
- * This function returns the version number associated with this kernel.
+ * This function returns the version number associated with this kernel.
*/
int sys_knlvsn(char *vsn)
@@ -101,7 +101,7 @@
#endif
/*
- * setgid() is implemented like SysV w/ SAVED_IDS
+ * setgid() is implemented like SysV w/ SAVED_IDS
*/
int sys_setgid(gid_t gid)
@@ -141,15 +141,15 @@
}
/*
- * setuid() is implemented like SysV w/ SAVED_IDS
- *
+ * setuid() is implemented like SysV w/ SAVED_IDS
+ *
* Note that SAVED_ID's is deficient in that a setuid root program
- * like sendmail, for example, cannot set its uid to be a normal
+ * like sendmail, for example, cannot set its uid to be a normal
* user and then switch back, because if you're root, setuid() sets
* the saved uid too. If you don't like this, blame the bright people
* in the POSIX committee and/or USG. Note that the BSD-style setreuid()
* will allow a root program to temporarily drop privileges and be able to
- * regain them by swapping the real and effective uid.
+ * regain them by swapping the real and effective uid.
*/
int sys_setuid(uid_t uid)
@@ -325,7 +325,7 @@
}
if (verified_memcpy_tofs(grouplist, pg, ((int)pi) * sizeof(gid_t)) != 0)
return -EFAULT;
-
+
}
return (int)pi;