performance - Multicore and thread aware.Net stopwatch.

Posted by 2018  •  article

The Time Stamp Counter ( TSC ) is a 64-bit register present on all x86 processors since the Pentium . It counts the number of cycles since reset. The instruction RDTSC returns the TSC in EDX:EAX. In x86-64 mode, RDTSC also clears the higher 32 bits of RAX and RDX . Its opcode is 0F 31 . [1] Pentium competitors such as the Cyrix 6x86 did not always have a TSC and may consider RDTSC an illegal instruction. Cyrix included a Time Stamp Counter in their MII .

Relying on the TSC also reduces portability, as other processors may not have a similar feature. Recent Intel processors include a constant rate TSC (identified by the kern.timecounter.invariant_tsc sysctl on FreeBSD or by the " constant_tsc " flag in Linux's /proc/cpuinfo ). With these processors, the TSC ticks at the processor's nominal frequency, regardless of the actual CPU clock frequency due to turbo or power saving states. Hence TSC ticks are counting the passage of time, not the number of CPU clock cycles elapsed.

On Windows platforms, Microsoft strongly discourages using the TSC for high-resolution timing for exactly these reasons, providing instead the Windows APIs QueryPerformanceCounter and QueryPerformanceFrequency . [2] On POSIX systems, a program can get similar function by reading the value of CLOCK_MONOTONIC clock using the clock_gettime function. [3]

"On a multiprocessor computer, it does not matter which processor the thread runs on. However, because of bugs in the BIOS or the Hardware Abstraction Layer (HAL), you can get different timing results on different processors. To specify processor affinity for a thread, use the ProcessThread . . :: . ProcessorAffinity method."

Stopwatch is a good choice, unless you need to measure long periods, and especially if you want high precision (it uses a high-resolution performance counter if available).

"On a multiprocessor computer, it does not matter which processor the thread runs on. However, because of bugs in the BIOS or the Hardware Abstraction Layer (HAL), you can get different timing results on different processors. To specify processor affinity for a thread, use the ProcessThread . . :: . ProcessorAffinity method."

A session is a correlation of all messages sent between two endpoints. Instancing refers to controlling the lifetime of user-defined service objects and their related InstanceContext objects. Concurrency is the term given to the control of the number of threads executing in an InstanceContext at the same time.

When a service contract sets the ServiceContractAttribute.SessionMode property to SessionMode.Required , that contract is saying that all calls (that is, the underlying message exchanges that support the calls) must be part of the same conversation. If a contract specifies that it allows sessions but does not require one, clients can connect and either establish a session or not. If the session ends and a message is sent over the same session-based channel an exception is thrown.

Sessions correlate a group of messages into a conversation. The meaning of that correlation is an abstraction. For instance, one session-based channel may correlate messages based on a shared network connection while another session-based channel may correlate messages based on a shared tag in the message body. The features that can be derived from the session depend on the nature of the correlation.

The Time Stamp Counter ( TSC ) is a 64-bit register present on all x86 processors since the Pentium . It counts the number of cycles since reset. The instruction RDTSC returns the TSC in EDX:EAX. In x86-64 mode, RDTSC also clears the higher 32 bits of RAX and RDX . Its opcode is 0F 31 . [1] Pentium competitors such as the Cyrix 6x86 did not always have a TSC and may consider RDTSC an illegal instruction. Cyrix included a Time Stamp Counter in their MII .

Relying on the TSC also reduces portability, as other processors may not have a similar feature. Recent Intel processors include a constant rate TSC (identified by the kern.timecounter.invariant_tsc sysctl on FreeBSD or by the " constant_tsc " flag in Linux's /proc/cpuinfo ). With these processors, the TSC ticks at the processor's nominal frequency, regardless of the actual CPU clock frequency due to turbo or power saving states. Hence TSC ticks are counting the passage of time, not the number of CPU clock cycles elapsed.

On Windows platforms, Microsoft strongly discourages using the TSC for high-resolution timing for exactly these reasons, providing instead the Windows APIs QueryPerformanceCounter and QueryPerformanceFrequency . [2] On POSIX systems, a program can get similar function by reading the value of CLOCK_MONOTONIC clock using the clock_gettime function. [3]

"On a multiprocessor computer, it does not matter which processor the thread runs on. However, because of bugs in the BIOS or the Hardware Abstraction Layer (HAL), you can get different timing results on different processors. To specify processor affinity for a thread, use the ProcessThread . . :: . ProcessorAffinity method."

Stopwatch is a good choice, unless you need to measure long periods, and especially if you want high precision (it uses a high-resolution performance counter if available).

"On a multiprocessor computer, it does not matter which processor the thread runs on. However, because of bugs in the BIOS or the Hardware Abstraction Layer (HAL), you can get different timing results on different processors. To specify processor affinity for a thread, use the ProcessThread . . :: . ProcessorAffinity method."

A session is a correlation of all messages sent between two endpoints. Instancing refers to controlling the lifetime of user-defined service objects and their related InstanceContext objects. Concurrency is the term given to the control of the number of threads executing in an InstanceContext at the same time.

When a service contract sets the ServiceContractAttribute.SessionMode property to SessionMode.Required , that contract is saying that all calls (that is, the underlying message exchanges that support the calls) must be part of the same conversation. If a contract specifies that it allows sessions but does not require one, clients can connect and either establish a session or not. If the session ends and a message is sent over the same session-based channel an exception is thrown.

Sessions correlate a group of messages into a conversation. The meaning of that correlation is an abstraction. For instance, one session-based channel may correlate messages based on a shared network connection while another session-based channel may correlate messages based on a shared tag in the message body. The features that can be derived from the session depend on the nature of the correlation.

A System.Diagnostics.Stopwatch instance can measure elapsed time for one interval, or the total of elapsed time across multiple intervals. In a typical System.Diagnostics.Stopwatch scenario, you call the Stopwatch.Start method, then eventually call the Stopwatch.Stop method, and then you check elapsed time using the Stopwatch.Elapsed property.

A System.Diagnostics.Stopwatch instance is either running or stopped; use Stopwatch.IsRunning to determine the current state of a System.Diagnostics.Stopwatch . Use Stopwatch.Start to begin measuring elapsed time; use Stopwatch.Stop to stop measuring elapsed time. Query the elapsed time value through the properties Stopwatch.Elapsed , Stopwatch.ElapsedMilliseconds , or Stopwatch.ElapsedTicks . You can query the elapsed time properties while the instance is running or stopped. The elapsed time properties steadily increase while the System.Diagnostics.Stopwatch is running; they remain constant when the instance is stopped.

By default, the elapsed time value of a System.Diagnostics.Stopwatch instance equals the total of all measured time intervals. Each call to Stopwatch.Start begins counting at the cumulative elapsed time; each call to Stopwatch.Stop ends the current interval measurement and freezes the cumulative elapsed time value. Use the Stopwatch.Reset method to clear the cumulative elapsed time in an existing System.Diagnostics.Stopwatch instance.

The Time Stamp Counter ( TSC ) is a 64-bit register present on all x86 processors since the Pentium . It counts the number of cycles since reset. The instruction RDTSC returns the TSC in EDX:EAX. In x86-64 mode, RDTSC also clears the higher 32 bits of RAX and RDX . Its opcode is 0F 31 . [1] Pentium competitors such as the Cyrix 6x86 did not always have a TSC and may consider RDTSC an illegal instruction. Cyrix included a Time Stamp Counter in their MII .

Relying on the TSC also reduces portability, as other processors may not have a similar feature. Recent Intel processors include a constant rate TSC (identified by the kern.timecounter.invariant_tsc sysctl on FreeBSD or by the " constant_tsc " flag in Linux's /proc/cpuinfo ). With these processors, the TSC ticks at the processor's nominal frequency, regardless of the actual CPU clock frequency due to turbo or power saving states. Hence TSC ticks are counting the passage of time, not the number of CPU clock cycles elapsed.

On Windows platforms, Microsoft strongly discourages using the TSC for high-resolution timing for exactly these reasons, providing instead the Windows APIs QueryPerformanceCounter and QueryPerformanceFrequency . [2] On POSIX systems, a program can get similar function by reading the value of CLOCK_MONOTONIC clock using the clock_gettime function. [3]

The Time Stamp Counter ( TSC ) is a 64-bit register present on all x86 processors since the Pentium . It counts the number of cycles since reset. The instruction RDTSC returns the TSC in EDX:EAX. In x86-64 mode, RDTSC also clears the higher 32 bits of RAX and RDX . Its opcode is 0F 31 . [1] Pentium competitors such as the Cyrix 6x86 did not always have a TSC and may consider RDTSC an illegal instruction. Cyrix included a Time Stamp Counter in their MII .

Relying on the TSC also reduces portability, as other processors may not have a similar feature. Recent Intel processors include a constant rate TSC (identified by the kern.timecounter.invariant_tsc sysctl on FreeBSD or by the " constant_tsc " flag in Linux's /proc/cpuinfo ). With these processors, the TSC ticks at the processor's nominal frequency, regardless of the actual CPU clock frequency due to turbo or power saving states. Hence TSC ticks are counting the passage of time, not the number of CPU clock cycles elapsed.

On Windows platforms, Microsoft strongly discourages using the TSC for high-resolution timing for exactly these reasons, providing instead the Windows APIs QueryPerformanceCounter and QueryPerformanceFrequency . [2] On POSIX systems, a program can get similar function by reading the value of CLOCK_MONOTONIC clock using the clock_gettime function. [3]

"On a multiprocessor computer, it does not matter which processor the thread runs on. However, because of bugs in the BIOS or the Hardware Abstraction Layer (HAL), you can get different timing results on different processors. To specify processor affinity for a thread, use the ProcessThread . . :: . ProcessorAffinity method."

Stopwatch is a good choice, unless you need to measure long periods, and especially if you want high precision (it uses a high-resolution performance counter if available).

"On a multiprocessor computer, it does not matter which processor the thread runs on. However, because of bugs in the BIOS or the Hardware Abstraction Layer (HAL), you can get different timing results on different processors. To specify processor affinity for a thread, use the ProcessThread . . :: . ProcessorAffinity method."


need help w/ multi-threaded, multi-CPU tick count.

Posted by 2018  •  article

 
 

71vtHtJFmfL