Hi Peter,
El Sun, Jan 04, 2009 at 08:55:50AM +0800 Peter Teoh ha dit:
> ah...two points:
>
> a. that the timer is NOT per-CPU. but a global entity. but many
> CPU can own the timer - as deduced from timer->base structure, but
> only one is running - based on timer->runng_base. correct? so
> logically the logic of clean deletion (making sure not being in used
> in another CPU) should be done in del_timer()....ie, detecting another
> CPU's running_timer is pointing to the current timer, if so then call
> del_timer_sync().
>
> ie, del_timer()->del_timer_sync()???
>
> b. concurrent modification via mod_timer(), and reading the source,
> it is synchronized by the per-CPU variable:
>
> cat /proc/kallsyms |grep tvec_bases |grep per_cpu
> c05b6b48 d per_cpu__tvec_bases
>
> But I cannot understand why the same can be done for del_timer()?
first of all, i'm far from being an expert, so i could be plain wrong.
as far as i understand from reading the source code, access to a struct
timer_list and its corresponding struct tvec_base is synchronized by
the spinlock tvec_base->lock, which is acquired in __mod_timer(),
del_timer(), try_to_del_timer_sync() (which is called by
del_timer_sync()), __run_timers(), ... this way the consistency of the
structures used by the timer subsystem is guaranteed.
the use of del_timer() is safe for what concerns the structures of the
timer subsystem. the following example shows the purpose of
del_timer_sync():
static struct timer_list timer;
static struct foo_struct *foo;
static void foo_timer(unsigned long arg)
{
...
int bar = foo->bar;
...
}
static int foo_open(struct inode *inode, struct file *filp)
{
...
foo = malloc(sizeof(struct foo_struct));
...
add_timer(&timer);
...
}
static int foo_release(struct inode * inode, struct file * file)
{
/* imagine the timer is executing right now */
del_timer(&timer);
/* the timer is no longer in the list of
pending timers
but it still could be running */
free(foo);
/* the timer could be still running and access
foo */
}
if we had used del_timer_sync() instead of del_timer() in release(),
we'd could safely free the memory of the foo structure, as we know for
sure that the timer is not running any more.
i'm not sure if i answered your question :)
--
Matthias Kaehlcke
Embedded Linux Engineer
Barcelona
If liberty means anything at all, it means the
right to tell people what they do not want to hear
(George Orwell)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [email protected]
Please read the FAQ at http://kernelnewbies.org/FAQ