[3427] in linux-scsi channel archive

home help back first fref pref prev next nref lref last post

Idea for SCSI kernel drivers: merge buffers

daemon@ATHENA.MIT.EDU (Marc SCHAEFER)
Sun Mar 1 13:16:42 1998

From: Marc SCHAEFER <schaefer@alphanet.ch>
Date: 	1 Mar 1998 19:00:40 +0100
Apparently-To: linux-scsi@vger.rutgers.edu
To: ;@unlisted-recipients (no To-header on input)

Most SCSI drivers (low-level) use scatter/gather. But do they
do something like this to not use too much memory in the
scripts of the hardware for mailboxes or scatter/gather
entries ?

      if (Cmnd->use_sg) {
         sg = (struct scatterlist *) Cmnd->request_buffer;
         ds = cmd->dataseg;
#if 0 /* standard */
         cmd->segment_cnt = Cmnd->use_sg;

         for (sg_count = 0; sg_count < Cmnd->use_sg; sg_count++) {
            ds->d_base = (void *) virt_to_bus(sg->address);
            ds->d_count = sg->length;
            sg++;
            ds++;
         }
#else /* trying to merge blocks fast */
         /* Initialisation */

         ds->d_base = (void *) virt_to_bus(sg->address);
         ds->d_count = sg->length;
         sg++;

         sg_count = 1;
         block_count = 1;

         while (sg_count < Cmnd->use_sg) {
            void *d_base = (void *) virt_to_bus(sg->address);

            if ((ds->d_base + ds->d_count) == (d_base)) {
               ds->d_count += sg->length; /* BUG: no overlap check */
               DEBUG_INTR(printk("merged, cnt=%d size=%ld\n", block_count, ds->d_count);)
            }
            else {
               /* We can't reuse the old one, commit it */
               ds++;
               block_count++;

               ds->d_base = (void *) virt_to_bus(sg->address);
               ds->d_count = sg->length;
            }
            sg++;
            sg_count++;
         }

         cmd->segment_cnt = block_count;
#endif
      }

The idea is to merge mailboxes/sg slots if the physical (DMA) address
are contiguous. Of course, integrity checks on the size of the
mailboxes and stuff has to be done before.

I saw that it happens all the times with the fs (at least in 2.0.x), and
it is bad to eat slots for nothing.

PS: I found that because the driver I am writing, for the Fujitsu MB86606,
    and I have not yet used the ``user program'' (ie the SCRIPTS engine),
    and thus I do scatter/gather with the CPU. This small optimization
    looked like it improved a bit my performance. The above is GPL'd
    from now on :-)  Maybe already someone had this idea. If you
    find a bug in the above, report it. Looks like it works. Next
    step is writing the user program :-)


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.rutgers.edu

home help back first fref pref prev next nref lref last post