3

コンテキストスイッチが発生したときのLinuxのタイムスタンプカウンターの詳細を誰かが知っているかどうか疑問に思っていますか?これまで私は、カーネルモードでもユーザーモードでも、TSC値は各クロックサイクルで1ずつ増加していると考えていました。TSCを使用してアプリケーションのパフォーマンスを測定したところ、5 MioClockCylesのパフォーマンス結果が得られました。次に、スケジューラーにいくつかの変更を加えました。これは、コンテキストスイッチにかなり長い時間がかかることを意味します。つまり、500.000サイクルではなく2Mioサイクルです。面白いことに、元のアプリケーションのパフォーマンスを再度測定すると、まだ5 Mioサイクルかかります...コンテキストスイッチに約2Mioクロックサイクルかかるので、なぜそれほど長くはかからなかったのでしょうか。(そして、アプリケーションの実行中に少なくとも3つのコンテキストが発生します)。

カーネルモード中にタイムスタンプカウンターが何らかの理由で非アクティブ化されていますか?または、コンテストの切り替え中にTSCのコンテンツが保存されますか?誰かが私に何が問題なのか指摘してくれたらありがとう!

4

2 に答える 2

1

As you can read on Wikipedia

With the advent of multi-core/hyperthreaded CPUs, systems with multiple CPUs, and "hibernating" operating systems, the TSC cannot be relied on to provide accurate results. The issue has two components: rate of tick and whether all cores (processors) have identical values in their time-keeping registers. There is no promise that the timestamp counters of multiple CPUs on a single motherboard will be synchronized. In such cases, programmers can only get reliable results by locking their code to a single CPU. Even then, the CPU speed may change due to power-saving measures taken by the OS or BIOS, or the system may be hibernated and later resumed (resetting the time stamp counter). Reliance on the time stamp counter also reduces portability, as other processors may not have a similar feature. Recent Intel processors include a constant rate TSC (identified by the constant_tsc flag in Linux's /proc/cpuinfo). With these processors the TSC reads at the processor's maximum rate regardless of the actual CPU running rate. While this makes time keeping more consistent, it can skew benchmarks, where a certain amount of spin-up time is spent at a lower clock rate before the OS switches the processor to the higher rate. This has the effect of making things seem like they require more processor cycles than they normally would.

于 2009-05-11T23:15:09.107 に答える
0

TSC は実際には、使用しているプロセッサのハードウェア構造であると思います。IE: TSC の読み取りは、実際には RDTSC プロセッサ オペコードを使用します。OSがその値を変更する方法があるとは思いません。最後の電源リセット以降、ティックごとに増加するだけです。

スケジューラーへの変更に関して、OS が実行中のプロセスを切り替えないようにマルチコア プロセッサを使用している可能性はありますか? スケジューラーの変更が有効になり始めるかどうかを確認するために、プログラムを呼び出したりプログラム内に呼び出しsched_yield()たりすることができます。sleep(0)

于 2009-05-11T18:30:41.113 に答える