Re: LTTng + dynamick tick

Mathieu Desnoyers <[email protected]>
Newsgroups gmane.linux.kernel.tracing
Message-ID <20061005153152.GA11799@Krystal>
* Deepak Saxena ([email protected]) wrote:
> 
> Hi,
> 
> I'm working on integrating LTTng into the MontaVista kernel which is
> basically 2.6.18 + the RT patch. One of the thing this patch adds and
> that we plan on supporting is dynamic ticks. Does the existing code 
> rely on having a timer tick? If so, how difficult of a task is it to
> not do so?
> 
> Tnx,
> ~Deepak
>

Hi Deepak,

I have put Thomas in CC, as he may think this is relevant to a wider range of
users.

We could try to use a modified version of 
include/linux/ktime.h : ktime_get_ts

It gets a monotonic time, which is good.
timespec is in ns, which is good too.
Now, about locking : 

kernel/hrtimer.c :

void ktime_get_ts(struct timespec *ts)
{
        struct timespec tomono;
        unsigned long seq;

        do {
                seq = read_seqbegin(&xtime_lock);
                getnstimeofday(ts);
                tomono = wall_to_monotonic;

        } while (read_seqretry(&xtime_lock, seq));

        set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec,
                                ts->tv_nsec + tomono.tv_nsec);
}

The problem here comes if the logging code is nested on the write lock. We need
to use a hack like the one found in include/asm-arm/ltt.h to fail after a few
loops.

In getnstimeofday :

void getnstimeofday (struct timespec *tv)
{
        unsigned long seq,sec,nsec;

        do {
                seq = read_seqbegin(&xtime_lock);
                sec = xtime.tv_sec;
                nsec = xtime.tv_nsec+time_interpolator_get_offset();
        } while (unlikely(read_seqretry(&xtime_lock, seq)));

        while (unlikely(nsec >= NSEC_PER_SEC)) {
                nsec -= NSEC_PER_SEC;
                ++sec;
        }
        tv->tv_sec = sec;
        tv->tv_nsec = nsec;
}

Another seqlock... same thing. There should be a _getnstimeofday which does not
take a read seqlock, as it is already taken by ktime_get_ts.

Now for timer.c : time_interpolator_get_offset :
It calls time_interpolator_get_counter(0), which uses a cmpxchg (this is good
for reentrancy!) :)

So, over all, I think we could switch to hrtimers for architectures which lack
proper synchronized TSC support, but with the seqlock tweaks I just mentioned.

Mathieu



OpenPGP public key:              http://krystal.dyndns.org:8080/key/compudj.gpg
Key fingerprint:     8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.