Find the answer to your Linux question:
Results 1 to 2 of 2
When below program is executed i got kernel panic. Please anybody check and let me know my mistake I compiled and executed in kernel 2.6.18.5 -----------------snip starts---------------- typedef struct queue_test ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    1

    Kernel Panic when schedule is called


    When below program is executed i got kernel panic.
    Please anybody check and let me know my mistake

    I compiled and executed in kernel 2.6.18.5

    -----------------snip starts----------------

    typedef struct queue_test
    {
    struct timer_list cache_timer;
    } q_test;

    static q_test Q;
    static int timer_starts = 0;
    static int first_time =1;
    static int global_value = 0;

    DECLARE_WAIT_QUEUE_HEAD(queue_test_waitq);

    static void queue_test_timer_handler(unsigned long a_cache)
    {
    printk("Timer Handler function called\n");
    if (!a_cache)
    {
    printk("Invalid entry \n");
    return;
    }

    printk("Wake up all queued packets\n");
    wake_up(&queue_test_waitq);

    printk("timer stopped\n");
    printk("============================\n");
    //timer_starts = 0;

    global_value = 1;
    }

    static unsigned int queue_test_prerouting(unsigned int hook,
    struct sk_buff **pskb,
    const struct net_device *in,
    const struct net_device *out,
    int (*okfn)(struct sk_buff *))
    {
    printk("Prerouting skb: %p\n", (*pskb));

    return NF_ACCEPT;
    }

    static int check_global_value()
    {
    if (global_value == 1)
    return 1;
    else
    return 0;
    }
    static unsigned int queue_test_forwarding(unsigned int hook,
    struct sk_buff **pskb,
    const struct net_device *in,
    const struct net_device *out,
    int (*okfn)(struct sk_buff *))
    {
    u32 genid;
    genid = atomic_read(&flow_cache_genid);

    if (first_time)
    {
    first_time = 0;
    printk("====================================\n");
    printk("First Packet: skb: %p \n", (*pskb));

    init_timer(&Q.cache_timer);
    Q.cache_timer.data = 1;
    Q.cache_timer.function = queue_test_timer_handler;
    Q.cache_timer.expires = jiffies + (60 * 1) * HZ;
    add_timer(&Q.cache_timer);
    }
    if (check_global_value() == 0)
    {
    DECLARE_WAITQUEUE(wait, current);
    add_wait_queue(&queue_test_waitq, &wait);

    set_current_state(TASK_INTERRUPTIBLE);
    schedule_timeout(5);
    set_current_state(TASK_RUNNING);

    remove_wait_queue(&queue_test_waitq, &wait);
    printk("Packet from queue\n");

    }

    return NF_ACCEPT;
    }

    static unsigned int queue_test_postrouting(unsigned int hook,
    struct sk_buff **pskb,
    const struct net_device *in,
    const struct net_device *out,
    int (*okfn)(struct sk_buff *))
    {
    printk("Post Routing \n");
    printk("Packet received: skb: %p \n", (*pskb));
    return NF_ACCEPT;
    }

    static struct nf_hook_ops queue_test_ops[] =
    {
    {
    .hook = queue_test_prerouting,
    .owner = THIS_MODULE,
    .pf = PF_INET,
    .hooknum = NF_IP_PRE_ROUTING,
    .priority = NF_IP_PRI_CONNTRACK + 1,
    },

    {
    .hook = queue_test_forwarding,
    .owner = THIS_MODULE,
    .pf = PF_INET,
    .hooknum = NF_IP_FORWARD,
    .priority = NF_IP_PRI_FILTER + 1,
    },

    {
    .hook = queue_test_postrouting,
    .owner = THIS_MODULE,
    .pf = PF_INET,
    .hooknum = NF_IP_POST_ROUTING,
    .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
    },
    };

    int __init queue_test_init(void)
    {
    int index;
    int ret;

    for (index = 0; index < ARRAY_SIZE(queue_test_ops); index++)
    {
    if ((ret = nf_register_hook(&queue_test_ops[index])) < 0)
    {

    return -1;
    }
    }

    return 0;
    }

    void __exit queue_test_exit(void)
    {
    int index;

    for (index = 0; index < ARRAY_SIZE(queue_test_ops); index++)
    {
    nf_unregister_hook(&queue_test_ops[index]);
    }
    }

    MODULE_LICENSE("GPL") ;

    module_init(queue_test_init) ;
    module_exit(queue_test_exit) ;
    --------------snip ends---------------

    Waiting for reply
    Thanks in advance..

    Sathish

  2. #2
    Just Joined!
    Join Date
    Jul 2008
    Posts
    15
    i had the same problem some time ago
    -> kernel panic in schedule()

    i'm not sure, but i think, the wait-queue stuff in your code is only for kernelversion <2.4

    for kernel 2.6 try:

    daemonize("%s",current->comm);
    DEFINE(wait);
    init_waitqueue_head(&queue_test_waitq);

    while(1) {
    wait_event_interruptible(queue_test_waitq, <condition>);
    do_smthg_if_woke_up();
    };

    i think, it's possible to change wait_event_interruptible() to wait_event_interruptible_timeout() or just wait_event_timeout()

    -> Linux Device Drivers - Google Buchsuche


    hope, this will help you, too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •