processor

how to set CPU affinity of a particular pthread?

心已入冬 提交于 2019-11-26 14:57:49
I'd like to specify the cpu-affinity of a particular pthread. All the references I've found so far deal with setting the cpu-affinity of a process (pid_t) not a thread (pthread_t). I tried some experiments passing pthread_t's around and as expected they fail. Am I trying to do something impossible? If not, can you send a pointer please? Thanks a million. This is a wrapper I've made to make my life easier. Its effect is that the calling thread gets "stuck" to the core with id core_id : // core_id = 0, 1, ... n-1, where n is the system's number of cores int stick_this_thread_to_core(int core_id)

CPU and Data alignment

别来无恙 提交于 2019-11-26 12:27:52
问题 Pardon me if you feel this has been answered numerous times, but I need answers to the following queries! Why data has to be aligned (on 2-byte / 4-byte / 8-byte boundaries)? Here my doubt is when the CPU has address lines Ax Ax-1 Ax-2 ... A2 A1 A0 then it is quite possible to address the memory locations sequentially. So why there is the need to align the data at specific boundaries? How to find the alignment requirements when I am compiling my code and generating the executable? If for e.g

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,

size of int variable

拥有回忆 提交于 2019-11-26 11:38:04
问题 How the size of int is decided? Is it true that the size of int will depend on the processor. For 32-bit machine, it will be 32 bits and for 16-bit it\'s 16. On my machine it\'s showing as 32 bits, although the machine has 64-bit processor and 64-bit Ubuntu installed. 回答1: It depends on the implementation. The only thing the C standard guarantees is that sizeof(char) == 1 and sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long) and also some representable minimum

Why is the size of L1 cache smaller than that of the L2 cache in most of the processors?

≯℡__Kan透↙ 提交于 2019-11-26 10:28:36
Why is the size of L1 cache smaller than that of the L2 cache in most of the processors ? There are different reasons for that. L2 exists in the system to speedup the case where there is a L1 cache miss. If the size of L1 was the same or bigger than the size of L2, then L2 could not accomodate for more cache lines than L1, and would not be able to deal with L1 cache misses. From the design/cost perspective, L1 cache is bound to the processor and faster than L2. The whole idea of caches is that you speed up access to the slower hardware by adding intermediate hardware that is more performing

Determine word size of my processor

你说的曾经没有我的故事 提交于 2019-11-26 09:33:34
问题 How do I determine the word size of my CPU? If I understand correct an int should be one word right? I\'m not sure if I am correct. So should just printing sizeof(int) would be enough to determine the word size of my processor? 回答1: Your assumption about sizeof(int) is untrue; see this. Since you must know the processor, OS and compiler at compilation time, the word size can be inferred using predefined architecture/OS/compiler macros provided by the compiler. However while on simpler and

How to determine whether a given Linux is 32 bit or 64 bit?

Deadly 提交于 2019-11-26 04:02:46
问题 When I type uname -a , it gives the following output. Linux mars 2.6.9-67.0.15.ELsmp #1 SMP Tue Apr 22 13:50:33 EDT 2008 i686 i686 i386 GNU/Linux How can I know from this that the given OS is 32 or 64 bit? This is useful when writing configure scripts, for example: what architecture am I building for? 回答1: Try uname -m. Which is short of uname --machine and it outputs: x86_64 ==> 64-bit kernel i686 ==> 32-bit kernel Otherwise, not for the Linux kernel, but for the CPU , you type: cat /proc

Why is the size of L1 cache smaller than that of the L2 cache in most of the processors?

瘦欲@ 提交于 2019-11-26 02:09:00
问题 Why is the size of L1 cache smaller than that of the L2 cache in most of the processors ? 回答1: There are different reasons for that. L2 exists in the system to speedup the case where there is a L1 cache miss. If the size of L1 was the same or bigger than the size of L2, then L2 could not accomodate for more cache lines than L1, and would not be able to deal with L1 cache misses. From the design/cost perspective, L1 cache is bound to the processor and faster than L2. The whole idea of caches