CLOCK_BOOTIME (commit cf87f8587)

Simo Sorce simo at samba.org
Wed Aug 10 08:59:59 UTC 2016


On Mon, Aug 01, 2016 at 03:00:16PM +0200, Volker Lendecke wrote:
> Hi, Simo!
> 
> Just talked to Björn Jacke: He told me that commit cf87f8587 was
> triggered by a suggestion you made. CLOCK_BOOTTIME is the better
> alternative than CLOCK_MONOTONIC. I don't fully understand it, but
> what I get is that CLOCK_BOOTTIME correctly takes care of a machine in
> suspend mode.
> 
> This of course makes a lot of sense for laptops, but it comes at
> a cost: If I run the attached program on a PPC machine I get that
> calling CLOCK_BOOTTIME is roughly 8 times more expensive than calling
> CLOCK_MONOTONIC. Christof Schmitt has figured out that this is due to
> CLOCK_BOOTTIME being a real syscall whereas CLOCK_MONOTONIC is a pure
> read from a kernel page like getpid() is.
> 
> [root at p8-10-rhel-71be-01 vlendeke]# time ./timetest 100000000
> real    0m26.443s
> user    0m7.298s
> sys     0m19.145s
> [root at p8-10-rhel-71be-01 vlendeke]# time ./timetest 100000000 mono
> real    0m3.253s
> user    0m3.244s
> sys     0m0.010s
> 
> Simo, do you really see the need for CLOCK_BOOTTIME for your RHEL
> deployments? Or could you live with CLOCK_MONOTONIC only?
> 
> If your customers need CLOCK_BOOTTIME, has RedHat the capability to
> make CLOCK_BOOTTIME a kernel page read too, so that it is just as
> cheap as CLOCK_MONOTONIC?

Hi Volker,
I think it is fine to use clock monotonic in the file server, the main reason
to use clock boottime was for winbind when used on laptops indeed.

If it is possible to use one for the file server and the other for winbindd
that would be nice, otherwise feel free to switch to monotonic.

HTH,
Simo.

> Thanks, Volker

> #include <stdio.h>
> #include <time.h>
> #include <errno.h>
> #include <string.h>
> #include <stdlib.h>
> 
> int main(int argc, const char *argv[])
> {
> 	int i, num;
> 	clockid_t clk = CLOCK_BOOTTIME;
> 
> 	if (argc < 2) {
> 		fprintf(stderr, "usage: %s num_iterations [mono]\n", argv[0]);
> 		return 1;
> 	}
> 
> 	if (argc == 3) {
> 		clk = CLOCK_MONOTONIC;
> 	}
> 
> 	num = atoi(argv[1]);
> 	for (i=0; i<num; i++) {
> 		struct timespec ts;
> 		int ret;
> 
> 		ret = clock_gettime(clk, &ts);
> 		if (ret == -1) {
> 			fprintf(stderr, "clock_gettime() failed: %s\n",
> 				strerror(errno));
> 			return 1;
> 		}
> 	}
> 
> 	return 0;
> }




More information about the samba-technical mailing list