Re: [ISSUE] sched/cgroup: Does cpu-cgroup still works fine nowadays?

From: Peter Zijlstra
Date: Wed May 14 2014 - 05:44:41 EST


On Wed, May 14, 2014 at 03:36:50PM +0800, Michael wang wrote:
> distro mount cpu-subsys under '/sys/fs/cgroup/cpu', create group like:
> mkdir /sys/fs/cgroup/cpu/A
> mkdir /sys/fs/cgroup/cpu/B
> mkdir /sys/fs/cgroup/cpu/C

Yeah, distro is on crack, nobody sane mounts anything there.

> and then:
> echo $$ > /sys/fs/cgroup/cpu/A/tasks ; ./my_tool -l
> echo $$ > /sys/fs/cgroup/cpu/B/tasks ; ./my_tool -l
> echo $$ > /sys/fs/cgroup/cpu/C/tasks ; ./my_tool 50
>
> the results in top is around:
>
> A B C
> CPU% 550 550 100

top doesn't do per-cgroup accounting, so how do you get these numbers,
per the above all instances of the prog are also called the same,
further making it error prone and difficult to get sane numbers.


> #include <sys/time.h>
> #include <unistd.h>
> #include <stdio.h>
> #include <pthread.h>
>
> pthread_mutex_t my_mutex;
>
> unsigned long long stamp(void)
> {
> struct timeval tv;
> gettimeofday(&tv, NULL);
>
> return (unsigned long long)tv.tv_sec * 1000000 + tv.tv_usec;
> }
> void consume(int spin, int total)
> {
> unsigned long long begin, now;
> begin = stamp();
>
> for (;;) {
> pthread_mutex_lock(&my_mutex);
> now = stamp();
> if ((long long)(now - begin) > spin) {
> pthread_mutex_unlock(&my_mutex);
> usleep(total - spin);
> pthread_mutex_lock(&my_mutex);
> begin += total;
> }
> pthread_mutex_unlock(&my_mutex);
> }
> }

Uh,.. that's just insane.. what's the point of having a multi-threaded
program do busy-wait loops if you then serialize the lot on a global
mutex such that only 1 thread can run at any one time?

How can one such prog ever consume more than 100% cpu.

Attachment: pgpQFZIlbjzlj.pgp
Description: PGP signature