# How to refer "kern.hz" in C ?



## liuwang (Apr 10, 2012)

Sir./Madam,

How to refer "kern.hz" in C 
Or how to refer "int hz" defined in subr_param.h in C?

I am writing a PCIe driver on FreeBSD.

Sincerely,
Liu


----------



## fonz (Apr 10, 2012)

liuwang said:
			
		

> Or how to refer "int hz" defined in subr_param.h in C?


That variable is not static, so in kernel space you should be able to simply write

```
extern int hz;
```
 However, seeing as this variable is not "exported" (for lack of a better word) by a header file, you're probably not supposed to mess with it directly. Aren't there any system calls that do what you want?

Fonz


----------



## liuwang (Apr 10, 2012)

fonz,

Thanks your help. 

The system call to get the 'hz' could not be found.

Seeing:

```
//'hz' is globally defined in /usr/src/sys/kern/subr_param.c
...
83 int	hz; 
...

//It is refered in /usr/src/sys/sys/kernel.h
...
61 extern int hz;				/* system clock's frequency */
...

//And is refered in /usr/src/sys/netinet/cc/cc_cubic.h
...
74 extern int hz;
...

//But when it is refered in mycode.h
...
extern int hz;
...
//and in mycode.c
...
m = hz / 1000;
...
//It reports error:
...
mycode.c:54:5: error: "hz" is not defined
...
```

Sincerely,
Liu


----------



## anon12b (Apr 26, 2012)

liuwang said:
			
		

> How to refer "kern.hz" in C



From userland you should look at sysctl(3), from the kernel check out http://fxr.watson.org/fxr/source/sys/sysctl.h.  With the caveat that it might not actually be the value you want.


----------

