LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2017, 11:36 AM   #1
TheLinuxQuestioner
LQ Newbie
 
Registered: Oct 2014
Posts: 6

Rep: Reputation: Disabled
gettime syscall


Hello,
I wanted to know whats the Implementation behind 'gettimeofday' syscall.

I made this testprogram:

Code:
#include <sys/time.h>
#include <stdio.h>

int main()
{
        struct timeval tv;
        while(1)
        {
                gettimeofday(&tv, NULL);
                printf("Zeit: %d s %d us\n", tv.tv_sec, tv.tv_usec);
                usleep(1000000);
        }
}
And called with strace ./time.

Code:
developer@linux-da23:~/development/trunk/projects/macs77> strace ./time
execve("./time", ["./time"], [/* 96 vars */]) = 0
brk(0)                                  = 0x16da000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f4c119a7000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=158421, ...}) = 0
mmap(NULL, 158421, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f4c11980000
close(3)                                = 0
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\10\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1925280, ...}) = 0
mmap(NULL, 3811872, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f4c113e5000
mprotect(0x7f4c1157f000, 2093056, PROT_NONE) = 0
mmap(0x7f4c1177e000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x199000) = 0x7f4c1177e000
mmap(0x7f4c11784000, 14880, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f4c11784000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f4c1197f000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f4c1197e000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f4c1197d000
arch_prctl(ARCH_SET_FS, 0x7f4c1197e700) = 0
mprotect(0x7f4c1177e000, 16384, PROT_READ) = 0
mprotect(0x600000, 4096, PROT_READ)     = 0
mprotect(0x7f4c119a8000, 4096, PROT_READ) = 0
munmap(0x7f4c11980000, 158421)          = 0
fstat(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f4c119a6000
write(1, "Zeit: 1488388237 s 962911 us\n", 29Zeit: 1488388237 s 962911 us
) = 29
nanosleep({1, 0}, NULL)                 = 0
write(1, "Zeit: 1488388238 s 963343 us\n", 29Zeit: 1488388238 s 963343 us
) = 29
I wonder why I dont see the call of 'gettimeofday' syscall.

I did a little research, could this be the reason?:

gettimeofday() on Linux is what's called a vsyscall and/or vdso. The mechanism maps a specific kernel-created code page into user memory, so that a few "syscalls" can be made without the overhead of a user/kernel context switch, but rather as "ordinary" function call.
 
Old 03-01-2017, 11:42 AM   #2
NoStressHQ
Member
 
Registered: Apr 2010
Location: Geneva - Switzerland ( Bordeaux - France / Montreal - QC - Canada)
Distribution: Slackware 14.2 - 32/64bit
Posts: 609

Rep: Reputation: 221Reputation: 221Reputation: 221
Have you tried... https://github.com/lattera/glibc/sea...q=gettimeofday ??
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
clock gettime variation rk_linux Programming 5 03-17-2011 08:42 PM
Syscall problems RepSTOSW Linux - Kernel 3 03-21-2010 11:57 AM
vfork syscall bandaru_sivakrishna Linux - Software 3 07-13-2009 11:21 PM
Syscall problems RepSTOSW Linux - Newbie 2 05-11-2009 08:00 PM
delay(), gettime() inside dos.h and conio.h in LINUX slickenside Programming 6 01-31-2004 05:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration