All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Xenomai <Xenomai@xenomai.org>
Subject: [Xenomai] RFC: slow tsc optimization
Date: Thu, 06 Sep 2012 09:24:58 +0200	[thread overview]
Message-ID: <50484FCA.50909@xenomai.org> (raw)


Hi,

The last few days, I have been working on getting the "rdtsc"
instruction replaced with a call to a tsc emulation function dynamically
at run time. It turned out to be easy with the Linux "alternative"
mechanism, since it implements replacements based on CPU capabilities,
and the TSC is such a capability. This modification allows to compile a
kernel with Xenomai that will run on any x86_32 platform.

Now, when running kernels without tsc using the PIT based tsc emulation,
I found out something pretty obvious, this PIT based tsc emulation is
slow, it takes 4us every time we call it. And the nucleus reads the tsc
a number of times when a timer interrupt happens up to the wake up of
the latency user-space task:
- at the very beginning of the timer interrupt
- after the execution of the latency thread timer
- in the timer programming function, to compute the timer delay
- in the middle of the context switch, if the "statistics collection"
feature is enabled
- in the xnpod_wait_thread_periodic function, after the context switch,
in order to compute the number of timer overruns.

That is 20us, and the thread is not yet running in user-space.

So, I have been thinking about reducing the number of calls to the PIT,
unfortunately keeping the last tsc value around and reusing it is a bit
heavy, and implies modifications which are completely useless for the
non PIT case (which should be the vast majority), and in fact, the tsc
emulation code has to keep the last read value, since it is required to
convert clocksources with less than 64 bits to a 64 bits value. So, I
propose the following approach:

The I-pipe core will provide two tsc reading functions:
ipipe_read_tsc which reads the counter
ipipe_read_tsc_fast which will read the tsc if the cpu has a tsc, or
return the last value read if the tsc is emulated.

This would result in lighter modifications of the nucleus.

Or is treating this problem in fact useless because nobody uses xenomai
without a tsc?

Regards.

-- 
                                                                Gilles.


             reply	other threads:[~2012-09-06  7:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-06  7:24 Gilles Chanteperdrix [this message]
2012-09-07 11:29 ` [Xenomai] RFC: slow tsc optimization Gilles Chanteperdrix
2012-09-08 19:30   ` Gilles Chanteperdrix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50484FCA.50909@xenomai.org \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=Xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.