Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Mar 2011 19:24:27 +1100
From:      Peter Jeremy <peterjeremy@acm.org>
To:        Jing Huang <jing.huang.pku@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: [GSoc] Timeconter Performance Improvements
Message-ID:  <20110325082427.GA56170@server.vk2pj.dyndns.org>
In-Reply-To: <AANLkTimbBohQmoPv19Qq2U6M70OBx%2BFBMiUAzQmqrTLK@mail.gmail.com>
References:  <AANLkTimbBohQmoPv19Qq2U6M70OBx%2BFBMiUAzQmqrTLK@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2011-Mar-24 17:00:02 +0800, Jing Huang <jing.huang.pku@gmail.com> wrote:
>         In this scenario, I plan to use both tsc and shared memory to
>calculate precise time in user mode. The shared memory includes
>system_time, tsc_system_time and factor_tsc-system_time.

This sounds like a reasonable approach to me.  Note that once we
implement a shared page, there is probably a variety of other
information we could usefully place on that page.

SunOS 4.x included a page of shared memory per CPU.  This was mapped
as an array (indexed by CPU number) at one address and the page
reflecting the current CPU was additionally mapped at another fixed
address.  This allowed a process to both refer to data on its CPU
as well any CPU on the system.

>         We also consider the CPU frequency, because tsc counter is
>related to it. When kernel changes CPU frequency, the shared memory
>should be update subsequently.

Two issues with this, particularly on x86 without invariant TSC:
- looking up the current CPU frequency may not be a cheap operation
- the reported CPU frequency appears to be just an approximate value,
  rather than the actual TSC frequency.

On 2011-Mar-24 21:34:35 +0800, Jing Huang <jing.huang.pku@gmail.com> wrote:
>    As I know, tsc counter is CPU specific. If the process running on
>a multi-core platform, we must consider switching problem. The one
>way, we can let the kernel to take of this. When switching to another
>CPU, the kernel will reset the shared memory according to the new CPU.

I'm not sure what the cost of managing this page mapping will be.

>The second way, we can use CPUID instruction to get the info of
>current CPU, which can be executed in user mode ether. At the same
>time, the kernel maintains shared memory for each CPU. When invoke
>gettimeofday, the function will calculate precise time with current
>CPU's shared memory.

This approach suffers from a race condition between the CPUID
instruction and accessing the appropriate shared page - there is the
potential for an interrupt causing the process to be switched to a
different CPU, resulting in an incorrect page being accessed.

--=20
Peter Jeremy

--PEIAKu/WMn1b1Hv9
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (FreeBSD)

iEYEARECAAYFAk2MUTsACgkQ/opHv/APuIeKAwCfSWSPl5kfMdsUC4D1gjM2cI0w
V0sAoJ7JccSKE4nR/t9s+Jl2wYECdZr0
=SC5O
-----END PGP SIGNATURE-----

--PEIAKu/WMn1b1Hv9--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110325082427.GA56170>