开发者

HZ variable not defined

开发者 https://www.devze.com 2022-12-15 07:31 出处:网络
I开发者_开发问答\'m trying to compile someone\'s code right now and the person is using a variable HZ (which I think stands for Hertz for the hertz of the cpu) but the compiler is complaining that the

I开发者_开发问答'm trying to compile someone's code right now and the person is using a variable HZ (which I think stands for Hertz for the hertz of the cpu) but the compiler is complaining that the variable is not defined. My guess is that the person didn't include the correct header file.

So does anyone know which header file, HZ is defined in?

Thanks

Edit: Compilation works on Debian g++ version 4.3.2

The setup I'm using - OSX Leopard 10.5.8, g++ version 4.0.1 is where it fails.


Paul's answer is correct, but I'll expand a little.

Linux has a compile-time option which determines the frequency of the kernel's timer. At approximately the frequency that HZ is defined to, the kernel scheduler will interrupt processes and begin its scheduling work. (A related feature is the DynTicks option, which elides the HZ value, and changes the interrupt frequency based on the workload.) The most common setting is 100. Highly responsive systems might use 1000. Recent kernel versions use a default of 250. Systems with heavy computational workloads might use a smaller value (to minimize the effect of the scheduler).

Thus it is a very Linux-specific value, and you'll only find it defined in /usr/include/asm/param.h

Since 100 is a common value, you might be safe in simply adding -DHZ=100 to your CXXFLAGS variable. This will by no means mean that the program will actually work on OS X, only that it might compile.


On my Linux box, it's defined in /usr/include/asm/param.h:#define HZ 100

I can't find a definition anywhere on my Mac OS X box.


it might be expected to come from the command line:

c++ -DHZ=1000 file.cpp -o file.o

hard to say more w/o more details. what operating system is this?


The answers seem no longer relevant on Linux Kernel 5.8.0 - There is only one line in the header file /usr/include/asm/param.h as shown below. I do not know why they did it that way.

#include <asm-generic/param.h>

You'll find #define HZ in /usr/include/asm-generic/param.h. The code below is found in my Ubuntu distribution and it is might be different than the one in Linux because it is an architecture-dependent value.

// ...
#ifndef HZ
#define HZ 100
#endif
// ....
0

精彩评论

暂无评论...
验证码 换一张
取 消