Skip to contentSkip to conversation

loading module

Xenomai-help Rodolfo 2 participants 8 messages May 23, 2007 2 messages not in the archive

lore
Share & tools
lore

Rodolfo

author
#0 lore raw

Hi,
I am totally new to Xenomai and have no experience with RTAI. I'm trying to load a kernel module that uses the native API for testing, but I get the following segmentation fault. Can anyone help me out?? Thanks

Running 2.6.20 Kernel and Xenomai is statically built into the Kernel, on a VIA Eden

----------------------------------------------------------------------------------------------------------------------------

Jun 13 03:58:04 login[345]: root login on 'ttyS0'

BusyBox v1.5.0 (2007-05-16 14:24:12 CEST) Built-in shell (ash) Enter 'help' for a list of built-in commands.

# cd usr
# insmod hallo.ko
task start<1>BUG: unable to handle kernel NULL pointer dereference at
virtual address 00000068
 printing eip:
c0157cd9
*pde = 00000000
Oops: 0000 [#1]
SMP
Modules linked in: hallo
CPU:    0
EIP:    0060:[<c0157cd9>]    Not tainted VLI
EFLAGS: 00010286   (2.6.20-default #4)
EIP is at rt_task_start+0x25/0x13e
eax: 00000060   ebx: 00000000   ecx: 00000000   edx: 00000286
esi: c8010780   edi: c118716c   ebp: 00000000   esp: c119de88
ds: 007b   es: 007b   ss: 0068
Process insmod (pid: 346, ti=c119c000 task=c77ccb10 task.ti=c119c000)
Stack: c011d8ea c800f088 c119deb0 c800f031 c118714c c1187000 c118716c
c800f580
       c800f021 c800f088 c0136cc4 c800f5c8 c033bda6 c800f58c 00000000
00001524
       00000230 c77fbba0 00000260 c0190271 00000000 00000000 00000000
00000000
Call Trace:
 [<c011d8ea>] printk+0x62/0xd6
 [<c800f031>] fun+0x0/0x57 [hallo]
 [<c800f021>] hello_init+0x20/0x30 [hallo]
 [<c0136cc4>] sys_init_module+0x1771/0x18b8
 [<c0190271>] do_sync_read+0xc7/0x10a
 [<c019f0bb>] dput+0x49/0x11f
 [<c0102dbf>] syscall_call+0x7/0xb
 =======================
Code: d8 5b 5e 5f 5d c3 55 57 56 53 83 ec 10 89 c6 8b 1d bc bc 46 c0 89
cd 89 54 24 0c ff 15 44 aa 37 c0 69 c0 c0 03 00 00 8d 44 18 60 <8b> 40
08 85
EIP: [<c0157cd9>] rt_task_start+0x25/0x13e SS:ESP 0068:c119de88
 Segmentation fault
#1 lore raw
Quoted 4 lines · Rodolfo

Hi,
I am totally new to Xenomai and have no experience with RTAI. I'm trying to load a kernel module that uses the native API for testing, but I get the following segmentation fault. Can anyone help me out??

Please post here the sources of your module.

Signature · 1 line
                                                 Gilles Chanteperdrix
author
#2 lore raw

here's the source of the testing module.

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <native/task.h>
#include <native/types.h>
#include <native/timer.h>
#include <rtdm/rtdm_driver.h>
#include <nucleus/pod.h>

MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Hello World Xenomai Application");

/************************* Global Variables ******************************/

RT_TASK thread;
RTIME timer_period_ns;
RTIME task_period_ns;
RTIME expected;
int timer_period_counts;
unsigned long overrun; // rt_task_wait_period() writes here overrun count.0 if everything OK

/************************* Periodic realtime thread **********************/

void fun(int dummy) {
    int count = 0;
    while(1) {
        ++count;
        rt_task_wait_period(&overrun);
        if ((count%100)==0) {
            rtdm_printk("Periode %d ist abgelaufen\n",count);
        }
    }
}

/************************* Initialisation *******************************/

static int hello_init(void)

{
    //testing rt_task_create(...);
    int count = 0;
    printk("task create");
    rt_task_create(&thread,"fun_task",3000,1,0);
    printk("created..");
    printk("task start");
    rt_task_start(&thread,fun,0);
    printk("started........");



    //timer_period_ns = 10000000;/*10ms*/
    /*timer_period_counts = start_rt_timer(nano2count(timer_period_ns));*/
//timer_period_counts=rt_timer_set_mode(rt_timer_ns2tsc(timer_period_ns));
    /* Calculate the start time for the task. */
    /* We set this to "now plus 10 periods"   */
    //expected = xnpod_get_time()  + 10 * timer_period_counts;

    /* Task period initialization */
    //task_period_ns =50000000;/*5ms*/
    /*rt_task_make_periodic(&thread, expected,
nano2count(task_period_ns));*/
    //rt_task_set_periodic(&thread, expected,
rt_timer_ns2tsc(task_period_ns));
    return 0;
}

/************************* Cleanup *********************************/

static void hello_exit(void)
{
/*stop_rt_timer();*/

/* Now delete our task */
// rt_task_delete(&thread);
}

module_init(hello_init);
module_exit(hello_exit);

Quoted 11 lines · Gilles Chanteperdrix
Quoted 5 lines · Rodolfo

Hi,
I am totally new to Xenomai and have no experience with RTAI. I'm trying to load a kernel module that uses the native API for testing, but I get the following segmentation fault. Can anyone help me out??

Please post here the sources of your module.

#3 lore raw
Quoted 1 line · Rodolfo

//timer_period_counts=rt_timer_set_mode(rt_timer_ns2tsc(timer_period_ns));

See
http://www.xenomai.org/documentation/branches/v2.3.x/html/api/group__native__timer.html#gffcb5eaef6c3a64a05445f6dafdbb155

the parameter of rt_timer_set_mode is a count of nanoseconds.

Quoted 2 lines
    //rt_task_set_periodic(&thread, expected,

rt_timer_ns2tsc(task_period_ns));

the task period passed to rt_task_set_periodic is a count of ticks, which should be obtained with rt_timer_ns2ticks.

Signature · 1 line
                                                 Gilles Chanteperdrix

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#5 lore raw

I got it to work with your example module, I recompiled the kernel without SMP support and it loaded.
I have to take a closer look at my own code now.
Thank you Peter and Gilles for your help.

Quoted 120 lines · Peter Feuerer

Hi Rudolfo,

I wrote a little text module some days ago, which does nearly the same like yours. I uploaded it to http://piie.net/files/xn-krn.tar.gz for you.

You should edit the line with the kernelpath of the Makefile. gl & hf
--peter

Quoted 105 lines · Rodolfo

here's the source of the testing module.

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <native/task.h>
#include <native/types.h>
#include <native/timer.h>
#include <rtdm/rtdm_driver.h>
#include <nucleus/pod.h>

MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Hello World Xenomai Application");

/************************* Global Variables ******************************/

RT_TASK thread;
RTIME timer_period_ns;
RTIME task_period_ns;
RTIME expected;
int timer_period_counts;
unsigned long overrun; // rt_task_wait_period() writes here overrun count.0 if everything OK

/************************* Periodic realtime thread **********************/

void fun(int dummy) {
    int count = 0;
    while(1) {
        ++count;
        rt_task_wait_period(&overrun);
        if ((count%100)==0) {
            rtdm_printk("Periode %d ist abgelaufen\n",count);
        }
    }
}

/************************* Initialisation *******************************/

static int hello_init(void)

{
    //testing rt_task_create(...);
    int count = 0;
    printk("task create");
    rt_task_create(&thread,"fun_task",3000,1,0);
    printk("created..");
    printk("task start");
    rt_task_start(&thread,fun,0);
    printk("started........");



    //timer_period_ns = 10000000;/*10ms*/
    /*timer_period_counts = start_rt_timer(nano2count(timer_period_ns));*/
//timer_period_counts=rt_timer_set_mode(rt_timer_ns2tsc(timer_period_ns));
    /* Calculate the start time for the task. */
    /* We set this to "now plus 10 periods"   */
    //expected = xnpod_get_time()  + 10 * timer_period_counts;

    /* Task period initialization */
    //task_period_ns =50000000;/*5ms*/
    /*rt_task_make_periodic(&thread, expected,
nano2count(task_period_ns));*/
    //rt_task_set_periodic(&thread, expected,
rt_timer_ns2tsc(task_period_ns));
    return 0;
}

/************************* Cleanup *********************************/

static void hello_exit(void)
{
/*stop_rt_timer();*/

/* Now delete our task */
// rt_task_delete(&thread);
}

module_init(hello_init);
module_exit(hello_exit);

Quoted 13 lines · Gilles Chanteperdrix
Quoted 6 lines · Rodolfo

Hi,
I am totally new to Xenomai and have no experience with RTAI. I'm trying to load a kernel module that uses the native API for testing, but I get the following segmentation fault. Can anyone help me out??

Please post here the sources of your module.

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 41 lines · Rodolfo
Quoted 12 lines · Gilles Chanteperdrix
Quoted 5 lines · Rodolfo

Hi,
I am totally new to Xenomai and have no experience with RTAI. I'm trying to load a kernel module that uses the native API for testing, but I get the following segmentation fault. Can anyone help me out??

Please post here the sources of your module.

here's the source of the testing module.

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <native/task.h>
#include <native/types.h>
#include <native/timer.h>
#include <rtdm/rtdm_driver.h>
#include <nucleus/pod.h>

MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Hello World Xenomai Application");

/************************* Global Variables ******************************/

RT_TASK thread;
RTIME timer_period_ns;
RTIME task_period_ns;
RTIME expected;
int timer_period_counts;
unsigned long overrun; // rt_task_wait_period() writes here overrun count.0 if everything OK

Quoted 7 lines

/************************* Periodic realtime thread **********************/

void fun(int dummy) {
    int count = 0;
    while(1) {
        ++count;
        rt_task_wait_period(&overrun);

Before calling rt_task_wait_period, you should have called rt_task_set_periodic. Here, rt_task_wait_period will continuously return
-EWOULDBLOCK and you will get a hard lockup.

Quoted 9 lines
        if ((count%100)==0) {
            rtdm_printk("Periode %d ist abgelaufen\n",count);
        }
    }
}

/************************* Initialisation *******************************/

static int hello_init(void)

Quoted 8 lines
{
    //testing rt_task_create(...);
    int count = 0;
    printk("task create");
    rt_task_create(&thread,"fun_task",3000,1,0);
    printk("created..");
    printk("task start");
    rt_task_start(&thread,fun,0);

At this point you do not know if rt_task_create succeeded, since you did not check its return value.

Quoted 8 lines
    printk("started........");
 
     
 
    //timer_period_ns = 10000000;/*10ms*/
    /*timer_period_counts = start_rt_timer(nano2count(timer_period_ns));*/

//timer_period_counts=rt_timer_set_mode(rt_timer_ns2tsc(timer_period_ns));

Setting the timer to periodic mode results in a lower timer resolution. Aperiodic mode, the default is usually fine.

Quoted 3 lines
    /* Calculate the start time for the task. */
    /* We set this to "now plus 10 periods"   */
    //expected = xnpod_get_time()  + 10 * timer_period_counts;

xnpod_get_time is not part of the native API, what you want is rt_timer_read.

Quoted 16 lines
 
    /* Task period initialization */
    //task_period_ns =50000000;/*5ms*/
    /*rt_task_make_periodic(&thread, expected,
nano2count(task_period_ns));*/
    //rt_task_set_periodic(&thread, expected,
rt_timer_ns2tsc(task_period_ns));
    return 0;
}

/************************* Cleanup *********************************/

static void hello_exit(void)
{
/*stop_rt_timer();*/

Quoted 6 lines

/* Now delete our task */
// rt_task_delete(&thread);
}

module_init(hello_init);
module_exit(hello_exit);

Why do you want to use Xenomai in kernel-space ? Since, as you said it, you are a beginner, you should use Xenomai in user-space. There, gdb will help you debug your segmentation faults.

Signature · 1 line
                                                 Gilles Chanteperdrix
author
#8 lore raw
Quoted 3 lines · Gilles Chanteperdrix

Why do you want to use Xenomai in kernel-space ? Since, as you said it, you are a beginner, you should use Xenomai in user-space. There, gdb will help you debug your segmentation faults.

I actually want to compare latencies between User-Space RT Tasks and Kernel RT Tasks.

#9 lore raw
Quoted 9 lines · Rodolfo
Quoted 3 lines · Gilles Chanteperdrix

Why do you want to use Xenomai in kernel-space ? Since, as you said it, you are a beginner, you should use Xenomai in user-space. There, gdb will help you debug your segmentation faults.

I actually want to compare latencies between User-Space RT Tasks and Kernel RT Tasks.

I would advise starting in user-space, adapting from user-space to kernel-space will then be straightforward.

If you want to compare latencies between user-space and kernel-space, you may have a look at the "latency" test. latency -t 0 outputs the user-space latency, latency -t 1 outputs the kernel-space latency.

Signature · 1 line
                                                 Gilles Chanteperdrix