Re: del_timer_sync(), function epilog and rmmod puzzle

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

 



Hi...

>
> I have just checked mailing list archive to make sure whether I have
> send out the message body correctly, and yes, it's there. So it must
> be my poor English which makes you can't understand my question, I
> feel lose, really. :-(

I felt obligated to reply. Do you mind? :)

> Anyhow, thanks for your kindly reply, and let me try it again. There
> are 3 questions about kernel 2.4:
>
> 1. According to "Linux device driver, 2e", Chapter 6 Flow of Time,
> Kernel Timers, it says:
>
> " If the timer function can restart the timer itself (a common
> pattern), you should also have a "stop timer'' flag that you set
> before calling del_timer_sync. The timer function should then check
> that flag and not reschedule itself with add_timer if the flag has
> been set."
>
> My question is: why should we have a "stop timer" flag here? Is there
> any problem without the flag?

Not sure, but if you want to re-arm the timer, you should use
mod_timer()/mod_timer_sync() instead IIRC. The later is preferred in
SMP.. It has something to do with atomicity/reentrancy, but can't
remember.

> The previous quoted text can be found online here:
> http://www.xml.com/ldd/chapter/book/ch06.html#t5
>
> 2. Say we have a "struct tq_struct my_task;", my question is: is there
> any way to indicate the status of my_task? Is it running? Is it in the
> task queue waiting for running? Or is it neither in the task queue nor
> running?

one thing for sure, if it's in the list...it is waiting for running.
If it's not in linked list (i forgot which one):
1. it isn't queued yet
or
2. it's already running

how about settting a flag? anything....simply a global variable
maybe....when it hit the function, set it let's say "1". When it's
about to leave, set it to "2". Comments?

> 3. Suppose my_task is created in a kernel module "foobar", and when we
> "rmmod foobar", we find that my_task is running, so we must waiting
> for its completion. A common way to do this is calling
> interruptible_sleep_on() in module_exit(), and let my_task.routine()
> to wake up it like this:
>
> void my_task_routine(void *dummy)
> {
>     .....
>     .....
>     wake_up_interruptible(...);
> }
>
> Well, as we know, function have its prolog and epilog. After
> wake_up_interruptible(), the rmmod thread executes and frees the
> memory of this module. At this time, memory containing epilog of the
> my_task_routine() was freed, it may oops when those "epilog" execute
> later on.
>
> My last question is: is this a trap? Or do I make some mistakes?

In your module_exit, make it check a flag. This flag is set by your
my_task_routine, let's say "2" means "i will quite". When this flag !=
2, do schedule(). repeat doing this in module_exit until it hits "2".
At least, this is my idea to offer.

regards,

Mulyadi.

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at 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