[fpc-pascal] Single threaded application on multicore CPU

LacaK lacak at zoznam.sk
Wed Jun 22 10:19:17 CEST 2016


>> I have simple Lazarus/FPC application (with no explicit threads) 
>> which does intensive calculations (local thresholding with big window 
>> size) on image, which is stored into memory as 2D byte array.
>> (so only memory access is done and some integer calculations)
>>
>> When I run this application and look at Task Manager or Resource 
>> Monitor I see, that all 4 cores "are used" (at least performance 
>> graph shows usage or in other words activity in graph increasees)
>> Total CPU usage is <= 25% (which points out to fact, that only 1/4 
>> cores is used)
>>
>> Why this ? As far as I expect, that single threaded application 
>> should use only one core, so I would expect activity only on one core 
>> not on all four cores
>> (I know that in theory CPU can switch single thread between cores, 
>> but I doubt that this is case (as switching has extra cost)... or is ?)
>
> Nailed it right there....
>
> All modern CPU automatically swaps running threads (unless affinity is 
> set) to other cores in case there is a high load. This is done from a
> heat perspective, since running on a single cores will make a local 
> heat spot on the dye - a things which is not prefered and also not really
> cost effient.

Thanks. It gives sense to me.
But moving thread from one core to another has any nonzero cost, does not ?
(So I wonder that CPU does that also when time for thread completion is 
not so much big ... so temperature of CPU does not increase so much)

-Laco.




More information about the fpc-pascal mailing list