1

I am writing a program that is supposed help run foreign code "safely". I also want to get the memory utilization and CPU compute time for the foreign code so I thought I would use cgroups.

I created a cgroup at /sys/fs/cgroup/cpuacct/<program name> and then add the executing foreign code's PID to the cgroups.procs file.

After the program executes I read /sys/fs/cgroup/cpuacct/<program name>/cpuacct.usage to try and get the CPU time.

According to this link the number I am getting is in USER_HZ.

After doing some reading and looking through the man pages of sysconf and getconf I ran the following command getconf CLK_TCK which output 100.

From the sysconf man pages this is "The number of clock ticks per second." So does that mean I can just take the number I got from cpuacct.usage and divide it by 100 to get my CPU compute time in seconds?

Because the numbers I am getting average out to about 270 million USER_HZs for a simple python program that creates a list of all the numbers between 0 and 1000 then prints the length of that list. And 2.7 million seconds doesn't sound right to me.

Can someone explain to me how to convert from USER_HZ to milliseconds? Or maybe I am going about this whole process wrong.

Thanks in advance!

1 Answer 1

0

From the sysconf man pages this is "The number of clock ticks per second." So does that mean I can just take the number I got from cpuacct.usage and divide it by 100 to get my CPU compute time in seconds?

As per Kernel doc here

.../sys/fs/cgroup/cpuacct.usage gives the CPU time (in nanoseconds)...

So you should divide the value by nanoseconds(1,000,000,000), not by USER_HZ.

Only cpuacct.stat values are in USER_HZ.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .