[GSoc] Timeconter Performance Improvements
peterjeremy at acm.org
Fri Mar 25 10:50:32 UTC 2011
On 2011-Mar-24 17:00:02 +0800, Jing Huang <jing.huang.pku at 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 at 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20110325/69f3a8a1/attachment.pgp
More information about the freebsd-hackers