Reg: problem in using High resolution Timer(hrtimer) - Linux

This is a discussion on Reg: problem in using High resolution Timer(hrtimer) - Linux ; Hello, I have written and compiled a kernel module on Linux Kernel version 2.6.22.8. The kernel module uses high precision timer to print after 2 sec continuosly , but as soon as I insert my module using modprobe ,the kernel ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Reg: problem in using High resolution Timer(hrtimer)

  1. Reg: problem in using High resolution Timer(hrtimer)

    Hello,
    I have written and compiled a kernel module on Linux Kernel
    version 2.6.22.8. The kernel module uses high precision timer to print
    after 2 sec continuosly , but as soon as I insert my module using
    modprobe ,the kernel goes in panic state.
    The kernel module code is as follows:
    __________________________________________________ ___________________________

    #include
    #include
    #include
    #include
    #include
    #include

    enum hrtimer_restart callback(struct hrtimer *); // return enum
    hrtimer_restart

    enum hrtimer_restart callback(struct hrtimer *timer)
    {
    printk(KERN_ALERT "TIMER INTERRUPTED\n");
    return HRTIMER_RESTART;
    }

    const long secs=2;
    const long nanosecs=0;

    struct hrtimer *timer;
    static int __init init_timer(void)
    {
    ktime_t kt;
    clockid_t which_clock=CLOCK_MONOTONIC; //CLOCK_REALTIME
    printk(KERN_ALERT "HRTTIMER inserted\n");
    kt=ktime_set(secs,nanosecs);
    timer = (struct hrtimer *)kmalloc(sizeof(struct hrtimer),GFP_KERNEL);
    hrtimer_init(timer,which_clock,HRTIMER_MODE_ABS);
    timer->function = &callback; // callback
    hrtimer_start(timer, kt,HRTIMER_MODE_ABS);
    printk(KERN_ALERT "HRTTIMER STARTED\n");
    return 0;
    }

    static void __exit exit_timer(void)
    {
    hrtimer_cancel(timer); //
    return;
    }

    MODULE_LICENSE("GPL");

    module_init(init_timer);
    module_exit(exit_timer);

    __________________________________________________ ______________________________

    To have panic logs I have also run the module on my UML guest
    kernel :
    The module log on when run on UML kernel are as follows:

    [root@localhost 2.6.22.8]# modprobe -f timer
    timer: no version magic, tainting kernel.
    HRTTIMER inserted

    EIP: 0073:[<080a1890>] CPU: 0 Tainted: GF ESP: 007b:0b5edefc
    EFLAGS: 00010246
    Tainted: GF
    EAX: 00000000 EBX: 0c00705a ECX: 0000001d EDX: 483e313c
    ESI: 0805e0e8 EDI: 00000001 EBP: 0b5edf0c DS: 007b ES: 007b
    081eabbc: [<08068098>] show_regs+0xb4/0xb9
    081eabe8: [<08058807>] segv+0x12d/0x272
    081eac8c: [<080586d5>] segv_handler+0x55/0x5a
    081eacac: [<08065cb8>] sig_handler_common_skas+0xd4/0xfc
    081eacd4: [<08062d1c>] sig_handler+0x34/0x44
    081eacec: [<08062eac>] handle_signal+0x4a/0x7a
    081ead0c: [<08064a7f>] hard_handler+0xf/0x14
    081ead1c: [<00e2d420>] 0xe2d420

    Kernel panic - not syncing: Kernel mode fault at addr 0x483e313c, ip
    0x80a1890

    EIP: 0073:[<400eee2e>] CPU: 0 Tainted: GF ESP: 007b:bfa62e40
    EFLAGS: 00000246
    Tainted: GF
    EAX: ffffffda EBX: 08066a88 ECX: 000054c1 EDX: 0805e0e8
    ESI: 0805e0e8 EDI: 0805e0e8 EBP: bfa62ec8 DS: 007b ES: 007b
    081eab24: [<08068098>] show_regs+0xb4/0xb9
    081eab50: [<08058b90>] panic_exit+0x25/0x3f
    081eab64: [<08077a08>] notifier_call_chain+0x21/0x46
    081eab84: [<08077aa3>] __atomic_notifier_call_chain+0x17/0x19
    081eaba0: [<08077aba>] atomic_notifier_call_chain+0x15/0x17
    081eabbc: [<0806c976>] panic+0x52/0xdd


    __________________________________________________ ___________________________


    Can somebody help me solving the problem?.



    regards
    bsahai


  2. Re: Reg: problem in using High resolution Timer(hrtimer)

    On Oct 29, 7:11 pm, bsahai wrote:
    > Hello,
    > I have written and compiled a kernel module on Linux Kernel
    > version 2.6.22.8. The kernel module uses high precision timer to print
    > after 2 sec continuosly , but as soon as I insert my module using
    > modprobe ,the kernel goes in panic state.
    > The kernel module code is as follows:
    > __________________________________________________ ___________________________
    >
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    >
    > enum hrtimer_restart callback(struct hrtimer *); // return enum
    > hrtimer_restart
    >
    > enum hrtimer_restart callback(struct hrtimer *timer)
    > {
    > printk(KERN_ALERT "TIMER INTERRUPTED\n");
    > return HRTIMER_RESTART;
    >
    > }
    >
    > const long secs=2;
    > const long nanosecs=0;
    >
    > struct hrtimer *timer;
    > static int __init init_timer(void)
    > {
    > ktime_t kt;
    > clockid_t which_clock=CLOCK_MONOTONIC; //CLOCK_REALTIME
    > printk(KERN_ALERT "HRTTIMER inserted\n");
    > kt=ktime_set(secs,nanosecs);
    > timer = (struct hrtimer *)kmalloc(sizeof(struct hrtimer),GFP_KERNEL);
    > hrtimer_init(timer,which_clock,HRTIMER_MODE_ABS);
    > timer->function = &callback; // callback
    > hrtimer_start(timer, kt,HRTIMER_MODE_ABS);
    > printk(KERN_ALERT "HRTTIMER STARTED\n");
    > return 0;
    >
    > }
    >
    > static void __exit exit_timer(void)
    > {
    > hrtimer_cancel(timer); //
    > return;
    >
    > }
    >
    > MODULE_LICENSE("GPL");
    >
    > module_init(init_timer);
    > module_exit(exit_timer);
    >
    > __________________________________________________ ______________________________
    >
    > To have panic logs I have also run the module on my UML guest
    > kernel :
    > The module log on when run on UML kernel are as follows:
    >
    > [root@localhost 2.6.22.8]# modprobe -f timer
    > timer: no version magic, tainting kernel.
    > HRTTIMER inserted
    >
    > EIP: 0073:[<080a1890>] CPU: 0 Tainted: GF ESP: 007b:0b5edefc
    > EFLAGS: 00010246
    > Tainted: GF
    > EAX: 00000000 EBX: 0c00705a ECX: 0000001d EDX: 483e313c
    > ESI: 0805e0e8 EDI: 00000001 EBP: 0b5edf0c DS: 007b ES: 007b
    > 081eabbc: [<08068098>] show_regs+0xb4/0xb9
    > 081eabe8: [<08058807>] segv+0x12d/0x272
    > 081eac8c: [<080586d5>] segv_handler+0x55/0x5a
    > 081eacac: [<08065cb8>] sig_handler_common_skas+0xd4/0xfc
    > 081eacd4: [<08062d1c>] sig_handler+0x34/0x44
    > 081eacec: [<08062eac>] handle_signal+0x4a/0x7a
    > 081ead0c: [<08064a7f>] hard_handler+0xf/0x14
    > 081ead1c: [<00e2d420>] 0xe2d420
    >
    > Kernel panic - not syncing: Kernel mode fault at addr 0x483e313c, ip
    > 0x80a1890
    >
    > EIP: 0073:[<400eee2e>] CPU: 0 Tainted: GF ESP: 007b:bfa62e40
    > EFLAGS: 00000246
    > Tainted: GF
    > EAX: ffffffda EBX: 08066a88 ECX: 000054c1 EDX: 0805e0e8
    > ESI: 0805e0e8 EDI: 0805e0e8 EBP: bfa62ec8 DS: 007b ES: 007b
    > 081eab24: [<08068098>] show_regs+0xb4/0xb9
    > 081eab50: [<08058b90>] panic_exit+0x25/0x3f
    > 081eab64: [<08077a08>] notifier_call_chain+0x21/0x46
    > 081eab84: [<08077aa3>] __atomic_notifier_call_chain+0x17/0x19
    > 081eaba0: [<08077aba>] atomic_notifier_call_chain+0x15/0x17
    > 081eabbc: [<0806c976>] panic+0x52/0xdd
    >
    > __________________________________________________ ___________________________
    >
    > Can somebody help me solving the problem?.
    >
    > regards
    > bsahai


    >From my quick reading, you seems to have segment violation problem.

    What architecture are you running (Intel, PPC, ARM ...)?


  3. Re: Reg: problem in using High resolution Timer(hrtimer)

    bsahai wrote:
    >
    > I have written and compiled a kernel module on Linux Kernel
    >version 2.6.22.8. The kernel module uses high precision timer to print
    >after 2 sec continuosly , but as soon as I insert my module using
    >modprobe ,the kernel goes in panic state.
    >...
    >
    >struct hrtimer *timer;
    >static int __init init_timer(void)
    >{
    >ktime_t kt;
    >clockid_t which_clock=CLOCK_MONOTONIC; //CLOCK_REALTIME
    >printk(KERN_ALERT "HRTTIMER inserted\n");
    >kt=ktime_set(secs,nanosecs);
    >timer = (struct hrtimer *)kmalloc(sizeof(struct hrtimer),GFP_KERNEL);
    >hrtimer_init(timer,which_clock,HRTIMER_MODE_ABS);
    >timer->function = &callback; // callback
    >hrtimer_start(timer, kt,HRTIMER_MODE_ABS);
    >printk(KERN_ALERT "HRTTIMER STARTED\n");
    >return 0;
    >}


    Maybe I'm misunderstanding this, but I would have guessed that you wanted
    HRTIMER_MODE_REL. By using CLOCK_MONOTONIC with an absolute time of 2
    seconds, you're asking for the timer to fire 2 seconds after the last boot,
    which has already expired.
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

  4. Re: Reg: problem in using High resolution Timer(hrtimer)

    On Oct 31, 12:24 pm, Tim Roberts wrote:
    > bsahai wrote:
    >
    > > I have written and compiled a kernel module on Linux Kernel
    > >version 2.6.22.8. The kernel module uses high precision timer to print
    > >after 2 sec continuosly , but as soon as I insert my module using
    > >modprobe ,the kernel goes in panic state.
    > >...

    >
    > >struct hrtimer *timer;
    > >static int __init init_timer(void)
    > >{
    > >ktime_t kt;
    > >clockid_t which_clock=CLOCK_MONOTONIC; //CLOCK_REALTIME
    > >printk(KERN_ALERT "HRTTIMER inserted\n");
    > >kt=ktime_set(secs,nanosecs);
    > >timer = (struct hrtimer *)kmalloc(sizeof(struct hrtimer),GFP_KERNEL);
    > >hrtimer_init(timer,which_clock,HRTIMER_MODE_ABS);
    > >timer->function = &callback; // callback
    > >hrtimer_start(timer, kt,HRTIMER_MODE_ABS);
    > >printk(KERN_ALERT "HRTTIMER STARTED\n");
    > >return 0;
    > >}

    >
    > Maybe I'm misunderstanding this, but I would have guessed that you wanted
    > HRTIMER_MODE_REL. By using CLOCK_MONOTONIC with an absolute time of 2
    > seconds, you're asking for the timer to fire 2 seconds after the last boot,
    > which has already expired.
    > --
    > Tim Roberts, t...@probo.com
    > Providenza & Boekelheide, Inc.- Hide quoted text -
    >
    > - Show quoted text -


    Yes you right it should be HRTTIMER_MOD_REL instead of
    HRTIMER_MOD_ABS ,but even after changing this the same problem is
    repeating ..I am again pasting the code and log (when run over UML
    kernel).

    PS: I am using Linux kernel 2.6.22.8 (i386)



    /
    ********************************code************** *************************************
    #include
    #include
    #include

    struct hrtimer *timer1;
    enum hrtimer_restart callback(struct hrtimer *); // return enum
    hrtimer_restart

    enum hrtimer_restart callback(struct hrtimer *timer)
    {
    printk(KERN_ALERT "\nTIME INTERRUPTED\n");
    return HRTIMER_RESTART;
    }

    const long secs=2;
    const long nanosecs=50;

    static int init_timer(void)
    {

    ktime_t kt;
    clockid_t which_clock=CLOCK_MONOTONIC; //CLOCK_REALTIME
    timer1=(struct hrtimer *)kmalloc(sizeof(struct hrtimer),GFP_ATOMIC);
    printk(KERN_ALERT "\ntimer:after malloc\n");

    kt=ktime_set(secs,nanosecs);
    printk(KERN_ALERT "\nBefore timer_init\n");
    hrtimer_init(timer1,which_clock,HRTIMER_MODE_REL);
    printk(KERN_ALERT "\nAfter Timer init\n");
    timer1->function = &callback;

    hrtimer_start(timer1, kt,HRTIMER_MODE_REL);
    printk(KERN_ALERT "\nAfter timer start\n");
    return 0;

    }

    static void exit_timer(void)
    {
    //hrtimer_cancel(timer);
    return;
    }
    MODULE_LICENSE("GPL");




    /*********Code ends here
    ************************************************** *************


    /*************************Log
    begins******************************************** *****************

    [root@localhost 2.6.22.8]# modprobe -f timer
    timer: no version magic, tainting kernel.

    EIP: 0073:[<080a1890>] CPU: 0 Tainted: GF ESP: 007b:0ad6aefc
    EFLAGS: 000102
    46
    Tainted: GF
    EAX: 00000000 EBX: 0b807480 ECX: 0b807480 EDX: 00000001
    ESI: 0805e0e8 EDI: 00000001 EBP: 0ad6af0c DS: 007b ES: 007b
    081eabbc: [<08068098>] show_regs+0xb4/0xb9
    081eabe8: [<08058807>] segv+0x12d/0x272
    081eac8c: [<080586d5>] segv_handler+0x55/0x5a
    081eacac: [<08065cb8>] sig_handler_common_skas+0xd4/0xfc
    081eacd4: [<08062d1c>] sig_handler+0x34/0x44
    081eacec: [<08062eac>] handle_signal+0x4a/0x7a
    081ead0c: [<08064a7f>] hard_handler+0xf/0x14
    081ead1c: [<00bdd420>] 0xbdd420

    Kernel panic - not syncing: Kernel mode fault at addr 0x1, ip
    0x80a1890

    EIP: 0073:[<400eee2e>] CPU: 0 Tainted: GF ESP: 007b:bf5ec9c0
    EFLAGS: 000002
    46
    Tainted: GF
    EAX: ffffffda EBX: 08066a88 ECX: 00005323 EDX: 0805e0e8
    ESI: 0805e0e8 EDI: 0805e0e8 EBP: bf5eca48 DS: 007b ES: 007b
    081eab24: [<08068098>] show_regs+0xb4/0xb9
    081eab50: [<08058b90>] panic_exit+0x25/0x3f
    081eab64: [<08077a08>] notifier_call_chain+0x21/0x46
    081eab84: [<08077aa3>] __atomic_notifier_call_chain+0x17/0x19
    081eaba0: [<08077aba>] atomic_notifier_call_chain+0x15/0x17
    081eabbc: [<0806c976>] panic+0x52/0xdd
    I?l?I?#?Jp??K`@?Lpk|M`"?NpM\O`?Pp/
    d`/
    GepZ?e`'gp x`Z?yp??z` 081eacd4: [<08062d1c>] sig_handler+0x34/EDTESTEWTEPTI
    Program terminated with signal SIGSEGV, Segmentation fault.
    The program no longer exists.handler+0xf/0x14
    (gdb) 1c: [<00bdd420>] 0xbdd420
    (gdb)

    /*************************log
    ends********************************************** ****************



    regards
    Bhagwan Sahai


+ Reply to Thread