LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 10-13-2021, 06:20 PM   #1
kennthhz
LQ Newbie
 
Registered: Jun 2020
Posts: 3

Rep: Reputation: Disabled
clock_gettime(CLOCK_THREAD_CPUTIME_ID) behavior on x86


My question on behavior of calling clock_gettime(CLOCK_THREAD_CPUTIME_ID). I looked at linux source code. There is a Posix implementation that coverts clock_id (CLOCK_THREAD_CPUTIME_ID) a specific kclock struct. Then does the per thread CPU tracking. But it seems like posix implementation will result in syscall. The code snippet is as follow https://elixir.bootlin.com/linux/lat...imers.c#L1085:

Code:
SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
        struct __kernel_timespec __user *, tp)
{
    const struct k_clock *kc = clockid_to_kclock(which_clock);
    struct timespec64 kernel_tp;
    int error;

    if (!kc)
        return -EINVAL;

    error = kc->clock_get_timespec(which_clock, &kernel_tp);

    if (!error && put_timespec64(&kernel_tp, tp))
        error = -EFAULT;

    return error;
}
The second path is vdso which doesn't incur syscall. However, it doesn't seem to support CLOCK_THREAD_CPUTIME_ID. My linux is built for x86. which path will it take and how to rationalize that in the source code? https://elixir.bootlin.com/linux/lat...eofday.c#L228:
Code:
static __always_inline int
__cvdso_clock_gettime_common(const struct vdso_data *vd, clockid_t clock,
                 struct __kernel_timespec *ts)
{
    u32 msk;

    /* Check for negative values or invalid clocks */
    if (unlikely((u32) clock >= MAX_CLOCKS))
        return -1;

    /*
     * Convert the clockid to a bitmask and use it to check which
     * clocks are handled in the VDSO directly.
     */
    msk = 1U << clock;
    if (likely(msk & VDSO_HRES))
        vd = &vd[CS_HRES_COARSE];
    else if (msk & VDSO_COARSE)
        return do_coarse(&vd[CS_HRES_COARSE], clock, ts);
    else if (msk & VDSO_RAW)
        vd = &vd[CS_RAW];
    else
        return -1;

    return do_hres(vd, clock, ts);
}
 
  


Reply

Tags
api, clock, kernel


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
ion SlackBuild fails with undefined reference to `clock_gettime'" xflow7 Slackware 1 08-09-2009 08:52 AM
clock_gettime(CLOCK_MONOTONIC,..) fails nathan2225 Programming 7 07-21-2006 10:35 AM
clock_gettime() issue AndreiCiprian Programming 0 03-28-2006 07:04 PM
POSIX.4 clock_gettime function collinss Programming 2 09-13-2005 07:55 AM
POSIX.4 clock_gettime function collinss Linux - General 1 11-24-2003 01:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 11:46 AM.

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