Improving the kernel/i386 timecounter performance
sobomax at FreeBSD.org
Mon Mar 30 18:31:14 PDT 2009
Peter Jeremy wrote:
> On 2009-Mar-29 08:35:45 +0800, David Xu <davidxu at freebsd.org> wrote:
>> Julian Elischer wrote:
>>> interestingly it is even feasible to have a per-thread page..
>>> it requires that the scheduler change a page table entry tough.
>> I will knock his door at midnight if he added such a heavy weight
>> task in the scheduler, TLB shutdown is horrible, and big code size
>> squeezing out data from CPU cache is not idea model.
>> scheduler should be as simple as just a context switching routine.
> If the TSC is not consistent between all cores (which is probably
> the most common situation at present), then using the TSC implies
> knowing which core you are executing on. From a userland perspective,
> the easiest way to do this is to have a page of data that varies
> depending on which core you are executing on.
It's not that easy, unless you can pin thread to a specific core before
reading that page. I.e. imagine the case when your thread reads per-cpu
page, get preempted and scheduled to a different core, then executes
RDTSC there, still thinking it got TSC reading from the first core. Even
if it does re-read from that page again after reading TSC to determine
if he has read the correct TSC, still it's possible (though not very
likely) that it has been preempted again and scheduled to the first core
after reading the TSC.
More information about the freebsd-current