Skip to content

Commit

Permalink
OS-6014 native gettimeofday should use comm page
Browse files Browse the repository at this point in the history
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Approved by: Jerry Jelinek <jerry.jelinek@joyent.com>
  • Loading branch information
pfmooney committed Mar 20, 2017
1 parent fc23aa9 commit 9be9378
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 126 deletions.
24 changes: 20 additions & 4 deletions usr/src/cmd/sgs/rtld/common/external.c
Expand Up @@ -22,7 +22,7 @@
/*
* Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2014 Garrett D'Amore <garrett@damore.org>
* Copyright 2016 Joyent, Inc.
* Copyright (c) 2017, Joyent, Inc.
*/

/*
Expand Down Expand Up @@ -723,9 +723,9 @@ isalnum(int c)

#if defined(__i386) || defined(__amd64)
/*
* Instead of utilizing the comm page for clock_gettime, rtld uses the raw
* syscall instead. Doing so decreases the surface of symbols needed from libc
* for a modest performance cost.
* Instead of utilizing the comm page for clock_gettime and gettimeofday, rtld
* uses the raw syscall instead. Doing so decreases the surface of symbols
* needed from libc for a modest performance cost.
*/
extern int __clock_gettime_sys(clockid_t, struct timespec *);

Expand All @@ -734,6 +734,22 @@ __clock_gettime(clockid_t clock_id, struct timespec *tp)
{
return (__clock_gettime_sys(clock_id, tp));
}

int
gettimeofday(struct timeval *tv, void *tz)
{
if (tv != NULL) {
/*
* Perform the same logic as the libc gettimeofday() when it
* lacks comm page support: Make the clock_gettime syscall and
* divide out the tv_usec field as required.
*/
__clock_gettime_sys(CLOCK_REALTIME, (timespec_t *)tv);
tv->tv_usec /= 1000;
}

return (0);
}
#endif /* defined(__i386) || defined(__amd64) */

/*
Expand Down
3 changes: 2 additions & 1 deletion usr/src/lib/libc/amd64/Makefile
Expand Up @@ -20,7 +20,7 @@
#
#
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2016 Joyent, Inc.
# Copyright (c) 2017, Joyent, Inc.
#
# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright 2013 Garrett D'Amore <garrett@damore.org>
Expand Down Expand Up @@ -1198,6 +1198,7 @@ $(PORTI18N_COND:%=pics/%) := \
pics/arc4random.o := CPPFLAGS += -I$(SRC)/common/crypto/chacha

pics/__clock_gettime.o := CPPFLAGS += $(COMMPAGE_CPPFLAGS)
pics/gettimeofday.o := CPPFLAGS += $(COMMPAGE_CPPFLAGS)

.KEEP_STATE:

Expand Down
60 changes: 0 additions & 60 deletions usr/src/lib/libc/amd64/sys/gettimeofday.s

This file was deleted.

3 changes: 2 additions & 1 deletion usr/src/lib/libc/i386/Makefile.com
Expand Up @@ -20,7 +20,7 @@
#
#
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2016 Joyent, Inc.
# Copyright (c) 2017, Joyent, Inc.
# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright 2013 Garrett D'Amore <garrett@damore.org>
#
Expand Down Expand Up @@ -1265,6 +1265,7 @@ $(PORTI18N_COND:%=pics/%) := \
pics/arc4random.o := CPPFLAGS += -I$(SRC)/common/crypto/chacha

pics/__clock_gettime.o := CPPFLAGS += $(COMMPAGE_CPPFLAGS)
pics/gettimeofday.o := CPPFLAGS += $(COMMPAGE_CPPFLAGS)

.KEEP_STATE:

Expand Down
50 changes: 50 additions & 0 deletions usr/src/lib/libc/i386/sys/gettimeofday.c
@@ -0,0 +1,50 @@
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/

/*
* Copyright (c) 2017, Joyent, Inc.
*/


#include "thr_uberdata.h"
#include <cp_defs.h>

#pragma weak _gettimeofday = gettimeofday

extern int __clock_gettime_sys(clockid_t, timespec_t *);

int
gettimeofday(struct timeval *tv, void *tz)
{
comm_page_t *cp = (comm_page_t *)__uberdata.ub_comm_page;

/*
* Perform a NULL check before attempting to store the result directly.
* The old fasttrop logic would perform this same check, but after the
* call into hrestime().
*/
if (tv == NULL) {
return (0);
}

/*
* Since timeval and timespec structs feature the same effective types
* and layout of their members, the conversion can be done in-place.
*/
if (cp != NULL && __cp_can_gettime(cp) != 0) {
__cp_clock_gettime_realtime(cp, (struct timespec *)tv);
} else {
__clock_gettime_sys(CLOCK_REALTIME, (struct timespec *)tv);
}
/* Convert from tv_nsec to tv_usec */
tv->tv_usec /= 1000;
return (0);
}
60 changes: 0 additions & 60 deletions usr/src/lib/libc/i386/sys/gettimeofday.s

This file was deleted.

0 comments on commit 9be9378

Please sign in to comment.