Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Sep 2000 05:56:12 +1100 (EST)
From:      King Fai Wong <kfw02@uow.edu.au>
To:        freebsd-questions@freebsd.org
Subject:   How to use gettimeofday() in kernel?
Message-ID:  <200009291856.FAA15467@wumpus.its.uow.edu.au>

next in thread | raw e-mail | index | archive | help
Hello, please help me to solve my problem

      I have a question on how to use the gettimeofday function inside
the kernel of FreeBSD. I included the libraries /sys/proc.h and 
/sys/sysproto.h in the file that will be compiled inside Kernel. The 
following is code that I added to a function inside that file. The 
purpose of my code is to get a current time when running this function.

#include <sys/proc.h>
#include <sys/time.h>
#include <sys/sysproto.h>

	:
	:

struct proc d;
struct gettimeofday_args T;

	:
	:

gettimeofday(&p, &T);
printf("Current time is: %ld and %ld\n", T.tp->sec, T.tp->usec);


When I compile the kernel, there's no error message for that file. But
I got the same value everytime I run this function(the time should be 
different). 

Output:
Sep 30 04:51:17 myClient / kernel: Current time is: 11010 and 3


I think that I used this gettimeofday function incorrectly.
Please tell me how to use this gettimeofday function correctly or tell
me somewhere I can find the information of the usage of:

int	gettimeofday __P((struct proc *, struct gettimeofday_args *))

This gettimeofday function is inside /sys/kern/kern_time.c and it's 
prototype is inside /sys/sys/sysproto.h

Actually, I have tried to use the other gettimeofday function outside 
kernel and compile the code with this function with cc and it was working
properly. This gettimeofday function's prototype is inside /sys/sys/time.h


Also, can you tell me that how to open a file inside the kernel or use 
the open function inside a program that run in kernel?

Thanks you very much!

Thomas


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200009291856.FAA15467>