Terry's interest prompted me to redo my algorithm a bit and write
    a program to test it with various combinations of base and size.
    I've included the program below.  My fixed algorithm appears to 
    produce the correct results, which is to generate the DEV_BSIZE
    aligned range that is fully enclosed within the supplied range.
    So, for example, a base of 0x0020 and a size of 0x0040 will
    produce a range of 0x0200 to 0x0200 (i.e. a null range, meaning
    we can't clear any dirty bits at all for that particular case).

    I am going to re-test with the new algorithm.

    Terry, or anyone... if you are interesting in trying out your 
    own algorithm fill it into algorithm2() below and enable the
    comparison code.

    Thanks for the comments, Terry!

                                        -Matt

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

static void algorithm1(int *base, int *size);
static void algorithm2(int *base, int *size);

int
main(int ac, char **av)
{
    int base;
    int size;

    for (base = 0; base <= 4096; base += 32) {
        for (size = 0; size <= 4096 - base; size += 32) {
            int nbase1 = base, nsize1 = size;
            int nbase2 = base, nsize2 = size;

            algorithm1(&nbase1, &nsize1);
            printf("%04x-%04x -> %04x-%04x\n", base, base + size, 
                nbase1, nbase1 + nsize1);
#if 0
            algorithm2(&nbase2, &nsize2);
            if (nbase1 != nbase2 || nsize1 != nsize2) {
                printf("%04x-%04x mismatch %04x-%04x vs %04x-%04x\n",
                    base, base + size,
                    nbase1, nbase1 + nsize1,
                    nbase2, nbase2 + nsize2
                );
            }
#endif
        }
    }
}

#define DEV_BSIZE       512

static void
algorithm1(int *base, int *size)
{
    int frag;

    if ((frag = *base & (DEV_BSIZE - 1)) != 0) {
        frag = DEV_BSIZE - frag;
        *base += frag;
        *size -= frag;
        if (*size < 0)
            *size = 0;
    }
    *size = *size & ~(DEV_BSIZE - 1);
}

#if 0

static void
algorithm2(int *base, int *size)
{
    ...
}

#endif

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to