cpu

How to create a CPU spike with a bash command

一个人想着一个人 提交于 2019-11-27 09:56:57
I want to create a near 100% load on a Linux machine. It's quad core system and I want all cores going full speed. Ideally, the CPU load would last a designated amount of time and then stop. I'm hoping there's some trick in bash. I'm thinking some sort of infinite loop. dimba You can also do dd if=/dev/zero of=/dev/null To run more of those to put load on more cores, try to fork it: fulload() { dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null & }; fulload; read; killall dd Repeat the command in the curly brackets as many

How can I get CPU load per core in C#?

我们两清 提交于 2019-11-27 09:33:05
How can I get CPU Load per core (quadcore cpu), in C#? Thanks :) You can either use WMI or the System.Diagnostics namespace. From there you can grab any of the performance counters you wish (however it takes a second (1-1.5s) to initialize those - reading values is ok, only initialization is slow) Code can look then like this: using System.Diagnostics; public static Double Calculate(CounterSample oldSample, CounterSample newSample) { double difference = newSample.RawValue - oldSample.RawValue; double timeInterval = newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec; if (timeInterval != 0)

What's the difference between conflict miss and capacity miss

流过昼夜 提交于 2019-11-27 09:26:17
问题 Capacity miss occurs because blocks are being discarded from cache because cache cannot contain all blocks needed for program execution (program working set is much larger than cache capacity). Conflict miss occurs in the case of set associative or direct mapped block placement strategies, conflict misses occur when several blocks are mapped to the same set or block frame; also called collision misses or interference misses. Are they actually very closely related? For example, if all the

Identifying the CPU architecture type using C#

一世执手 提交于 2019-11-27 09:02:45
I want to check which CPU architecture is the user running, is it i386 or X64 or AMD64. I want to do it in C#. I know i can try WMI or Registry. Is there any other way apart from these two? My project targets .NET 2.0! You could also try (only works if it's not manipulated): System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") What led me here is checking for a 32 vs 64 bit OS. the highest rated answer is looking at the setting for the Current process . After not finding an answer I found the following setting. Hope this works for you. bool is64 = System.Environment

Which Java thread is hogging the CPU?

一笑奈何 提交于 2019-11-27 09:02:02
问题 Let's say your Java program is taking 100% CPU. It has 50 threads. You need to find which thread is guilty. I have not found a tool that can help. Currently I use the following very time consuming routine: Run jstack <pid> , where pid is the process id of a Java process. The easy way to find it is to run another utility included in the JDK - jps . It is better to redirect jstack's output to a file. Search for "runnable" threads. Skip those that wait on a socket (for some reason they are still

Assembly CPU frequency measuring algorithm

守給你的承諾、 提交于 2019-11-27 08:40:43
What are the common algorithms being used to measure the processor frequency? Nathan Fellman Intel CPUs after Core Duo support two Model-Specific registers called IA32_MPERF and IA32_APERF. MPERF counts at the maximum frequency the CPU supports, while APERF counts at the actual current frequency. The actual frequency is given by: You can read them with this flow ; read MPERF mov ecx, 0xe7 rdmsr mov mperf_var_lo, eax mov mperf_var_hi, edx ; read APERF mov ecx, 0xe8 rdmsr mov aperf_var_lo, eax mov aperf_var_hi, edx but note that rdmsr is a privileged instruction and can run only in ring 0. I don

GCC's reordering of read/write instructions

偶尔善良 提交于 2019-11-27 07:29:58
Linux's synchronization primitives (spinlock, mutex, RCUs) use memory barrier instructions to force the memory access instructions from getting re-ordered. And this reordering can be done either by the CPU itself or by the compiler. Can someone show some examples of GCC produced code where such reordering is done ? I am interested mainly in x86. The reason I am asking this is to understand how GCC decides what instructions can be reordered. Different x86 mirco architectures (for ex: sandy bridge vs ivy bridge) use different cache architecture. Hence I am wondering how GCC does effective

Good resources on how to program PEBS (Precise event based sampling) counters?

爷,独闯天下 提交于 2019-11-27 07:17:16
问题 I have been trying to log all memory accesses of a program, which as I read seems to be impossible. I have been trying to see to what extent can I go to log atleast a major portion of the memory accesses, if not all. So I was looking to program the PEBS counters in such a way that I could see changes in the number of memory access samples collected. I wanted to know if I can do this by modifying the counter-reset value of PEBS counters. (Usually this goes to zero, but I want to set it to a

How to get the number of CPUs in Linux using C?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 06:35:59
Is there an API to get the number of CPUs available in Linux? I mean, without using /proc/cpuinfo or any other sys-node file... I've found this implementation using sched.h: int GetCPUCount() { cpu_set_t cs; CPU_ZERO(&cs); sched_getaffinity(0, sizeof(cs), &cs); int count = 0; for (int i = 0; i < 8; i++) { if (CPU_ISSET(i, &cs)) count++; } return count; } But, isn't there anything more higher level using common libraries? Владимир Николайчук #include <stdio.h> #include <sys/sysinfo.h> int main(int argc, char *argv[]) { printf("This system has %d processors configured and " "%d processors

Performance 32 bit vs. 64 bit arithmetic

我与影子孤独终老i 提交于 2019-11-27 06:34:45
问题 Are native 64 bit integer arithmetic instructions slower than their 32 bit counter parts (on x86_64 machine with 64 bit OS)? Edit: On current CPUs such Intel Core2 Duo, i5/i7 etc. 回答1: It depends on the exact CPU and operation. On 64-bit Pentium IVs, for example, multiplication of 64-bit registers was quite a bit slower. Core 2 and later CPUs have been designed for 64-bit operation from the ground up. Generally, even code written for a 64-bit platform uses 32-bit variables where values will