cpu

Java编发编程之原子操作与CAS原理分析

╄→尐↘猪︶ㄣ 提交于 2019-12-06 20:02:31
引子 之前的文章我们简单介绍了线程安全的三个核心概念可见性和有序性和原子性, 那么这篇文章我们就来分析一下原子性操作的实现原理 原子操作 原子本意为不可分割的最小粒子,而原子操作则为不可中断的一个或者系列操作 注意的是对一部分操作保持了原子性并不意味着就不会发生线程安全问题, 而是要保证整个临界区都是原子性的。 下面我们来分析一下cpu和java中如何实现原子操作 Cpu实现 CPU使用基于缓存加锁或者总线加锁实现多个CPU的原子性操作 cpu自动保证基本内存操作的原子性 处理器保证从系统内存当中读取或者写入一个字节是原子的,意思是当一个处理器读取一个字节时,其他处理器不能访问这个字节的内存地址,但是复杂的内存操作处理器不能自动保证其原子性,比如跨总线宽度,跨多个缓存行,跨页表的访问。 但是处理器提供总线锁定和缓存锁定两个机制来保证复杂内存操作的原子性 总线加锁使同时只有一个cpu能独占内存进行操作 原因是有可能多个处理器同时从各自的缓存中读取变量,分别进行操作,然后分别写入系统内存当中。那么想要保证读改写共享变量的操作是原子的,就必须保证CPU1读改写共享变量的时候,CPU2不能操作缓存了该共享变量内存地址的缓存。 处理器使用总线锁就是来解决这个问题的。所谓总线锁就是使用处理器提供的一个LOCK#信号,当一个处理器在总线上输出此信号时,其他处理器的请求将被阻塞住

Does GRUB switch to protected mode?

牧云@^-^@ 提交于 2019-12-06 17:29:00
问题 I would like to ask if it is GRUB that switch the CPU to protected mode during boot up or is it the Linux kernel that does it. And also I would like to ask - is the kernel itself (vmlinuz) an ELF or is it plain binary format? Thanks. 回答1: GRUB does drop you in protected mode. The GRUB Multiboot Specification (version 0.6.96) Section 3.2 tells you this ‘CR0’ Bit 31 (PG) must be cleared. Bit 0 (PE) must be set. Other bits are all undefined. And CR0 Register mapping tells you that the system

x86 and x64 share instruction set?

余生长醉 提交于 2019-12-06 16:49:23
I don't know how 32bit application can run on a 64bit OS. My understanding is 32bit/64bit refers to register size. An instruction set should be different as they have different sizes of register. But I know there is x86-64 instruction set that is the 64bit version of the x86 instruction set. Is the reason we can run 32bit application on 64bit OS is because of the x86-64? If so, why are 32bit applications sometimes not compatible in 64bit windows? Why do we need WOW64? (Sometimes we are asked to choose which version to install.) Does x64 instruction set have any other instruction set except x86

Measuring the CPU frequency scaling effect

会有一股神秘感。 提交于 2019-12-06 16:13:11
Recently I am trying to measure the effect of the cpu scaling. Is it accurate if I use this clock to measure it? template<std::intmax_t clock_freq> struct rdtsc_clock { typedef unsigned long long rep; typedef std::ratio<1, clock_freq> period; typedef std::chrono::duration<rep, period> duration; typedef std::chrono::time_point<rdtsc_clock> time_point; static const bool is_steady = true; static time_point now() noexcept { unsigned lo, hi; asm volatile("rdtsc" : "=a" (lo), "=d" (hi)); return time_point(duration(static_cast<rep>(hi) << 32 | lo)); } }; Update : According to the comment from my

how to get android cpu temperature programmatically

柔情痞子 提交于 2019-12-06 14:09:56
问题 Tried this but got 0.0 and on physical device nothing found.. Any way to get cpu temperature in android SensorManager mySensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); Sensor AmbientTemperatureSensor = mySensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); if (AmbientTemperatureSensor != null) { mySensorManager.registerListener( AmbientTemperatureSensorListener, AmbientTemperatureSensor, SensorManager.SENSOR_DELAY_NORMAL); } private final SensorEventListener

Thrust: How to directly control where an algorithm invocation executes?

荒凉一梦 提交于 2019-12-06 13:25:21
问题 The following code has no information that may lead it to run at CPU or GPU. I wonder where is the "reduce" operation executed? #include <thrust/iterator/counting_iterator.h> ... // create iterators thrust::counting_iterator<int> first(10); thrust::counting_iterator<int> last = first + 3; first[0] // returns 10 first[1] // returns 11 first[100] // returns 110 // sum of [first, last) thrust::reduce(first, last); // returns 33 (i.e. 10 + 11 + 12) Furthermore, thrust::transform_reduce( thrust:

Checking CPU Popcount from C#

谁说胖子不能爱 提交于 2019-12-06 12:42:40
Does anyone know how to check the cpu in C# if it supports popcount(population count)? C++ is easy but trying to do some C++ to C# conversion with some chess code. Thanks much. IvoTops I have yet to find an easy way to detect and use special CPU instructions in C#. There are several options, none of them nice; asmjit a function that does popcount x86/x64 CPUID in C# mono has a simd library with datatype support (not popcount I guess) Use a C++ DLL (probably way slower because of overhead) .. I never went that way and implemented a C# popcount; /// <summary> /// Count the number of bits set to

Predicting DXL Memory and CPU Usage

点点圈 提交于 2019-12-06 12:35:51
问题 Has anyone had any success in predicting or profiling DXL applications for memory and CPU usage? I have a script that opens, closes, and modifies modules, possibly hundreds or even thousands of modules. I want to know, or least have a rough idea, how many modules I can run through the script before running out of memory. Cross posts: http://smartdxl.com/forum/viewtopic.php?f=1&t=602 https://www.ibm.com/developerworks/community/forums/html/topic?id=c5d4cc33-9986-463e-a73b-36523e6add7a&ps=25 来源

How does CPU make data request via TLBs and caches?

两盒软妹~` 提交于 2019-12-06 11:50:02
问题 I am observing the last few Intel microarchitectures (Nehalem/SB/IB and Haswell). I am trying to work out what happens (at a fairly simplified level) when a data request is made. So far I have this rough idea: Execution engine makes data request "Memory control" queries the L1 DTLB If the above misses, the L2 TLB is now queried At this point two things can happen, a miss or a hit: If its a hit the CPU tries L1D/L2/L3 caches, page table and then main memory/hard disk in that order? If its a

WCF and threadpool responsiveness under high processor usage

大城市里の小女人 提交于 2019-12-06 11:49:51
We are having trouble controlling a long running process that uses WCF to send start/stop commands. The problem seems to be that WCF does not respond to the requests when the CPU load is high. Unfortunately, high CPU on as many cores as possible is necessary for the application in question as it needs to perform a large number of numeric calculations. Could the problem be related to the use of the thread pool to dispatch requests in WCF? This (somewhat dated) link suggests that it could: " we don't spin up new threads when CPU usage is higher than 80% " WCF has throttling mechanism that