Hi all,

I have a question about the %Ld formatter of the printk function. I have the
follwoing test performed: The conditions and the result are below. The
"Diff" is that, that I expect, but whats about the doubled output of the
same variable (t1 and t2)??. Depends this on the %Ld formatter ???? I'm not
sure. Has anybody an explanation for this?? In addition the "printf"
function produces a negative output, when the value does not fits into a
32bit integer (section DMESG).

My equipment: Pentium III, 256MB Ram, Mandrake 7.2, RTLinux-3.0 and
prepatched kernel 2.2.18 from fsmlabs.

Thanks

Thomas


------------------ Module Code -------------------------

#include <rtl.h>
#include <time.h>
#include <pthread.h>

static pthread_t thread;

static void * start_routine(void *arg)
{
        int i;
        hrtime_t t1;
        hrtime_t t2;
        hrtime_t diff;

        struct sched_param p;
        p . sched_priority = 1;
        pthread_setschedparam (pthread_self(), SCHED_FIFO, &p);

        rtl_printf("RTLinux thread starts on CPU%d\n", rtl_getcpuid());

        for (i = 0; i < 100; i++) {
                t1 = gethrtime();
                rtl_printf("Before Sleep: gethrtime()=[%Ld][%Ld]\n", t1,t1);
                usleep(500000);
                t2 = gethrtime();
                rtl_printf("After Sleep:  gethrtime()=[%Ld][%Ld]\n", t2,t2);
                diff = t2 - t1;
                rtl_printf("Diff=[%Ld]\n", diff);
        }
        return (void *) 0;
}


int init_module(void)
{
        int ret;
        pthread_attr_t attr;

        pthread_attr_init (&attr);

        ret = pthread_create (&thread, &attr, start_routine, 0);
        if (ret) {
                rtl_printf("failed to create a thread\n");
                return ret;
        }

        return 0;
}


void cleanup_module(void)
{
        pthread_delete_np (thread);
}


-------------- Makefile -------------------------------
ALL= test.o


CC                       = gcc

USER_CFLAGS = -O2 -Wall

RTL_FLAGS       = `rtl-config --cflags`
RTL_INCL        = /usr/include/rtlinux
        
all : $(ALL)

test.o: test.c
        $(CC) -c $(RTL_FLAGS) -I$(RTL_INCL) $<

clean:
        rm -f *.o

---------------- DMESG Output -------------------------------
RTLinux thread starts on CPU0
Before Sleep: gethrtime()=[1342973024][823]
After Sleep:  gethrtime()=[1842995584][823]
Diff=[500022560]
Before Sleep: gethrtime()=[1843014144][823]
After Sleep:  gethrtime()=[-1951933984][823]
Diff=[500019168]
Before Sleep: gethrtime()=[-1951919584][823]
After Sleep:  gethrtime()=[-1451899328][823]
Diff=[500020256]
Before Sleep: gethrtime()=[-1451883744][823]
After Sleep:  gethrtime()=[-951864864][823]
Diff=[500018880]
Before Sleep: gethrtime()=[-951849792][823]
After Sleep:  gethrtime()=[-451824448][823]
Diff=[500025344]
Before Sleep: gethrtime()=[-451803584][823]
After Sleep:  gethrtime()=[48217120][824]
Diff=[500020704]
Before Sleep: gethrtime()=[48235104][824]
After Sleep:  gethrtime()=[548257280][824]
Diff=[500022176]
----------------------------------------------------------------------------
------

**************************************************************
Dipl.-Ing. (FH) 
Thomas Lehwald
RUETZ Technologies              Tel:   089 / 3 56 10 - 268
Abteilung E-Technik                     Fax:  089 / 3 56 10 - 111
Ingolstaedter Strasse 18                80807 Muenchen
email: [EMAIL PROTECTED]
****************************************************

----- End of forwarded message from [EMAIL PROTECTED] -----
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to