Confused about task queues...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi
I'm confused about task queues.

Say for example I have the code:

static void my_bh1(void *unused)
{
    // Bottom half function.
    printk(KERN_INFO "my_bh\n");
}

int init_module(void)
{
    struct tq_struct    tq;

    tq.sync = 0;
    tq.routine = my_bh1;
    tq.data = NULL;
    queue_task(&tq, &tq_immediate);
    mark_bh(IMMEDIATE_BH);

    return 0;
}

This causes my PC to lockup !!!

But if I declare the tq_struct as a global,
i.e.
static struct tq_struct   tq;

...then everything is OK, and my_bh1() gets called.
I assume this is because, when the tq_struct is declared locally the
queue_task simple stores a pointer to it (adds it to a list) rather than
make a copy of it, and thus when it goes out of scope the kernel tries to
access memory in never-never land (and all hell breaks loose).

Presuming this is true, here's my question:

How do you suggest I handle/allocate the tq_struct structure that I pass to
queue_task() ?

And here's why I'm asking the question...

* I declare a global tq_struct structure in my PCI widget driver
* My PCI card interrupts
* My interrupt handler gets called
* I make a note of the interrupt and use the global tq_struct structure to
   schedule my_bh1() func
* I exit the interrupt handler
* Immediately I'm interrupted again (before the bottom half function had a
   chance to run)
* I now fillout the same global tq_struct structure with a pointer to a
   different routine (say my_bh2() )

Looks to me if my_bh1() is never going to get called now because its been
overwritten.  8(

The only way I can see this working is if I dynamically allocate memory in
the interrupt routine for the tq_struct structure (using GFP_ATOMIC).
If this is a better/correct way to handle this situation then second
question:
Where is it safe to deallocate the memory ?
Can I do it in the bottom half routine ( i.e. my_bh1() ) ?

I hope I haven't been to confusing.
I've tried to look through the kernel code for examples, but they all seem
to statically allocate the task queue structure, Hmmm.

If this is the wrong place to ask this question please point me somewhere
else.
Thanks for your time
regards
dom
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux