Thin granularity of the nanolayer is ineffective in C ++ program on linux

I am trying to periodically call a fetch function in a C ++ stream on my Linux machine. I would like to restart my function after a very short period, ideally 1 ms, but I find that the power (in W) consumed during 1 ms is prohibitively high: the system works at twice the power level, as when my period is 5 ms . Low power consumption is a serious issue for the functionality I want.

In particular,

void* loop_and_sample(void* arg) { while(1) { sample(); nanosleep((struct timespec[]){{0,1000000}}, NULL); } } 

Accepts 2x power:

 void* loop_and_sample(void* arg) { while(1) { sample(); nanosleep((struct timespec[]){{0,5000000}}, NULL); } } 

I determined that the difference in the energy consumption of my sampler at 2 frequencies is negligible and that the additional energy consumption comes from a sleep call. That is, even if I comment on the sample () line in both fragments above, the second still takes up half the power. Any ideas on how I can reduce the power consumed by a sleep call?

FYI, I am running Ubuntu 3.2.0 on a 24-core Intel Xeon processor, and a search in my / boot / config for frequency shows the following:

 cat /boot/config-3.2.0-48-generic | egrep 'HZ' CONFIG_RCU_FAST_NO_HZ=y CONFIG_NO_HZ=y # CONFIG_HZ_100 is not set CONFIG_HZ_250=y # CONFIG_HZ_300 is not set # CONFIG_HZ_1000 is not set CONFIG_HZ=250 CONFIG_MACHZ_WDT=m 

However, by running this script: http://www.advenage.com/topics/linux-timer-interrupt-frequency.php , I found that interrupting the kernel timer is at least 4016 Hz (this is 4 times the frequency I would like to try ) Thank you for your help!

+4
source share
1 answer

The problem is almost certainly NOT a sleep call, but the fact that your processor cannot shut down quickly and quickly. The CPU will almost certainly not instantly use less energy after you fall asleep, so it will take some time. When you go to bed for a longer period of time, the CPU can reduce energy consumption better.

I'm not sure that you can do something here, although the potential beautification of your processor may help to use energy when waking up more often.

+1
source

Source: https://habr.com/ru/post/1491951/


All Articles