What is the difference between getrusage (RUSAGE_THREAD, ...) and clock_gettime (CLOCK_THREAD_CPUTIME_ID, ...) on Linux?

The question pretty much says it all. According to the man page for getrusage(), it returns:

           struct timeval ru_utime; /* user CPU time used */
           struct timeval ru_stime; /* system CPU time used */

According to the man page, clock_gettime()it returns:

   CLOCK_THREAD_CPUTIME_ID (since Linux 2.6.12)
          Thread-specific CPU-time clock.

So, how does (stream-specific) "user / system processor usage time" differ from the hourly time of a processor with a specific thread?

Obviously, I ask because I see the difference between the two in the application that I ported to Linux (from user RTOS). This application has an internal profiling function implemented with tick()and functions tock(). Since I was digging into this, I degenerated one part of my application:

tick()
// code commented out
tock()

tick() , , tock() , , , . tick() tock() getrusage(), 0 out, 1000us 10000us ( , ​​ 1 100 ). tick() tock() clock_gettime(), 13us ( 75us 100us, ).

VIRT_CPU_ACCOUNTING / VIRT_CPU_ACCOUNTING_GEN. , , , , getrusage(), 1000us 1000.

, , clock_gettime() , , -. , .

+4
1

getrusage (RUSAGE_THREAD,...) clock_gettime (CLOCK_THREAD_CPUTIME_ID,...) Linux?

clock_gettime(CLOCK_THREAD_CPUTIME_ID, …) task_sched_runtime(p), p->se.sum_exec_runtime, struct task_struct *p - current.

getrusage(RUSAGE_THREAD, …) task_cputime_adjusted(current, &utime, &stime), [a], [b] ; , Linux CONFIG_VIRT_CPU_ACCOUNTING_NATIVE:

, .

, . , , clock_gettime().

, ( ). .

, .

, Linux.

0

Source: https://habr.com/ru/post/1622262/


All Articles