cpu

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

*爱你&永不变心* 提交于 2019-11-26 12:03:40
问题 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? 回答1: #include <stdio.h> #include <sys/sysinfo.h> int main(int argc,

FLOPS per cycle for sandy-bridge and haswell SSE2/AVX/AVX2

a 夏天 提交于 2019-11-26 12:03:23
I'm confused on how many flops per cycle per core can be done with Sandy-Bridge and Haswell. As I understand it with SSE it should be 4 flops per cycle per core for SSE and 8 flops per cycle per core for AVX/AVX2. This seems to be verified here, How do I achieve the theoretical maximum of 4 FLOPs per cycle? ,and here, Sandy-Bridge CPU specification . However the link below seems to indicate that Sandy-bridge can do 16 flops per cycle per core and Haswell 32 flops per cycle per core http://www.extremetech.com/computing/136219-intels-haswell-is-an-unprecedented-threat-to-nvidia-amd . Can someone

Is setInterval CPU intensive?

拥有回忆 提交于 2019-11-26 10:59:57
问题 I read somewhere that setInterval is CPU intensive. I created a script that uses setInterval and monitored the CPU usage but didn\'t notice a change. I want to know if there is something I missed. What the code does is check for changes to the hash in the URL (content after #) every 100 milliseconds and if it has changed, load a page using AJAX. If it has not changed, nothing happens. Would there be any CPU issues with that. 回答1: I don't think setInterval is inherently going to cause you

Finding out the CPU clock frequency (per core, per processor)

▼魔方 西西 提交于 2019-11-26 10:35:07
问题 Programs like CPUz are very good at giving in depth information about the system (bus speed, memory timings, etc.) However, is there a programmatic way of calculating the per core (and per processor, in multi processor systems with multiple cores per CPU) frequency without having to deal with CPU specific info. I am trying to develop a anti cheating tool (for use with clock limited benchmark competitions) which will be able to record the CPU clock during the benchmark run for all the active

Get CPU/GPU/memory information

只谈情不闲聊 提交于 2019-11-26 10:29:04
问题 I need to get any information about the CPU/GPU/memory.The number of cores, memory value, memory and cpu usage... I found a way to do this for IE:How to Use JavaScript to Find Hardware Information solutions for other browsers I do not know. Any idea how to do it? maybe webgl has access to information about your computer? or flash? or any other technology? Thank you very much 回答1: This code will print GPU infos an will list all info you can have with the performance object of this browser

On 32-bit CPUs, is an &#39;integer&#39; type more efficient than a &#39;short&#39; type?

╄→гoц情女王★ 提交于 2019-11-26 09:52:58
问题 On a 32-bit CPU, an integer is 4 bytes and a short integer is 2 bytes. If I am writing a C/C++ application that uses many numeric values that will always fit within the provided range of a short integer, is it more efficient to use 4 byte integers or 2 byte integers? I have heard it suggested that 4 byte integers are more efficient as this fits the bandwidth of the bus from memory to the CPU. However, if I am adding together two short integers, would the CPU package both values in a single

Threads configuration based on no. of CPU-cores

99封情书 提交于 2019-11-26 08:04:14
问题 Scenario : I have a sample application and I have 3 different system configuration - - 2 core processor, 2 GB RAM, 60 GB HHD, - 4 core processor, 4 GB RAM, 80 GB HHD, - 8 core processor, 8 GB RAM, 120 GB HHD In order to effectively exploit the H/W capabilities for my application, I wish to configure the no. of threads at the application level. However, I wish to do this only after a thorough understanding of system capabilities. Could there be some way(system/modus/tool) to determine the

What does “rep; nop;” mean in x86 assembly? Is it the same as the “pause” instruction?

扶醉桌前 提交于 2019-11-26 08:01:38
问题 What does rep; nop mean? Is it the same as pause instruction? Is it the same as rep nop (without the semi-colon)? What\'s the difference to the simple nop instruction? Does it behave differently on AMD and Intel processors? (bonus) Where is the official documentation for these instructions? Motivation for this question After some discussion in the comments of another question, I realized that I don\'t know what rep; nop; means in x86 (or x86-64) assembly. And also I couldn\'t find a good

How many CPU cycles are needed for each assembly instruction?

江枫思渺然 提交于 2019-11-26 07:35:59
I heard there is Intel book online which describes the CPU cycles needed for a specific assembly instruction, but I can not find it out (after trying hard). Could anyone show me how to find CPU cycle please? Here is an example, in the below code, mov/lock is 1 CPU cycle, and xchg is 3 CPU cycles. // This part is Platform dependent! #ifdef WIN32 inline int CPP_SpinLock::TestAndSet(int* pTargetAddress, int nValue) { __asm { mov edx, dword ptr [pTargetAddress] mov eax, nValue lock xchg eax, dword ptr [edx] } // mov = 1 CPU cycle // lock = 1 CPU cycle // xchg = 3 CPU cycles } #endif // WIN32 BTW:

What happens after a L2 TLB miss?

送分小仙女□ 提交于 2019-11-26 07:34:13
问题 I\'m struggling to understand what happens when the first two levels of the Translation Lookaside Buffer result in misses? I am unsure whether \"page walking\" occurs in special hardware circuitry, or whether the page tables are stored in the L2/L3 cache, or whether they only reside in main memory. 回答1: (Some of this is x86 and Intel-specific. Most of the key points apply to any CPU that does hardware page walks. I also discuss ISAs like MIPS that handle TLB misses with software.) Modern x86