From: Michael wang <wangyun@linux.vnet.ibm.com>
To: Peter Zijlstra <peterz@infradead.org>, Rik van Riel <riel@redhat.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>, Mike Galbraith <efault@gmx.de>,
Alex Shi <alex.shi@linaro.org>, Paul Turner <pjt@google.com>,
Mel Gorman <mgorman@suse.de>,
Daniel Lezcano <daniel.lezcano@linaro.org>
Subject: Re: [ISSUE] sched/cgroup: Does cpu-cgroup still works fine nowadays?
Date: Wed, 14 May 2014 15:36:50 +0800 [thread overview]
Message-ID: <53731D12.7040804@linux.vnet.ibm.com> (raw)
In-Reply-To: <20140513142328.GE2485@laptop.programming.kicks-ass.net>
[-- Attachment #1: Type: text/plain, Size: 3484 bytes --]
Hi, Peter
On 05/13/2014 10:23 PM, Peter Zijlstra wrote:
[snip]
>
> I you want to investigate !spinners, replace the ABC with slightly more
> complex loads like: https://lkml.org/lkml/2012/6/18/212
I've done a little reform, enabled multi-threads and add a mutex,
please check the code below for details.
I built it by:
gcc -o my_tool cgroup_tool.c -lpthread
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
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
While only './my_tool 50' was running, it require around 300%.
And this could also be reproduced by dbench, stress combination like:
echo $$ > /sys/fs/cgroup/cpu/A/tasks ; dbench 6
echo $$ > /sys/fs/cgroup/cpu/B/tasks ; stress -c 6
echo $$ > /sys/fs/cgroup/cpu/C/tasks ; stress -c 6
Now it seems more like a generic problem... will keep investigating, please
let me know if there are any suggestions :)
Regards,
Michael Wang
#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);
}
}
struct my_data {
int spin;
int total;
};
void *my_fn_sleepy(void *arg)
{
struct my_data *data = (struct my_data *)arg;
consume(data->spin, data->total);
return NULL;
}
void *my_fn_loop(void *arg)
{
while (1) {};
return NULL;
}
int main(int argc, char **argv)
{
int period = 100000; /* 100ms */
int frac;
struct my_data data;
pthread_t last_thread;
int thread_num = sysconf(_SC_NPROCESSORS_ONLN) / 2;
void *(*my_fn)(void *arg) = &my_fn_sleepy;
if (thread_num <= 0 || thread_num > 1024) {
fprintf(stderr, "insane processor(half) size %d\n", thread_num);
return -1;
}
if (argc == 2 && !strcmp(argv[1], "-l")) {
my_fn = &my_fn_loop;
printf("loop mode enabled\n");
goto loop_mode;
}
if (argc < 2) {
fprintf(stderr, "%s <frac> [<period>]\n"
" frac -- [1-100] %% of time to burn\n"
" period -- [usec] period of burn/sleep cycle\n",
argv[0]);
return -1;
}
frac = atoi(argv[1]);
if (argc > 2)
period = atoi(argv[2]);
if (frac > 100)
frac = 100;
if (frac < 1)
frac = 1;
data.spin = (period * frac) / 100;
data.total = period;
loop_mode:
pthread_mutex_init(&my_mutex, NULL);
while (thread_num--) {
if (pthread_create(&last_thread, NULL, my_fn, &data)) {
fprintf(stderr, "Create thread failed\n");
return -1;
}
}
printf("Threads never stop, CTRL + C to terminate\n");
pthread_join(last_thread, NULL);
pthread_mutex_destroy(&my_mutex); //won't happen
return 0;
}
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
[-- Attachment #2: cgroup_tool.c --]
[-- Type: text/x-csrc, Size: 2042 bytes --]
#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);
}
}
struct my_data {
int spin;
int total;
};
void *my_fn_sleepy(void *arg)
{
struct my_data *data = (struct my_data *)arg;
consume(data->spin, data->total);
return NULL;
}
void *my_fn_loop(void *arg)
{
while (1) {};
return NULL;
}
int main(int argc, char **argv)
{
int period = 100000; /* 100ms */
int frac;
struct my_data data;
pthread_t last_thread;
int thread_num = sysconf(_SC_NPROCESSORS_ONLN) / 2;
void *(*my_fn)(void *arg) = &my_fn_sleepy;
if (thread_num <= 0 || thread_num > 1024) {
fprintf(stderr, "insane processor(half) size %d\n", thread_num);
return -1;
}
if (argc == 2 && !strcmp(argv[1], "-l")) {
my_fn = &my_fn_loop;
printf("loop mode enabled\n");
goto loop_mode;
}
if (argc < 2) {
fprintf(stderr, "%s <frac> [<period>]\n"
" frac -- [1-100] %% of time to burn\n"
" period -- [usec] period of burn/sleep cycle\n",
argv[0]);
return -1;
}
frac = atoi(argv[1]);
if (argc > 2)
period = atoi(argv[2]);
if (frac > 100)
frac = 100;
if (frac < 1)
frac = 1;
data.spin = (period * frac) / 100;
data.total = period;
loop_mode:
pthread_mutex_init(&my_mutex, NULL);
while (thread_num--) {
if (pthread_create(&last_thread, NULL, my_fn, &data)) {
fprintf(stderr, "Create thread failed\n");
return -1;
}
}
printf("Threads never stop, CTRL + C to terminate\n");
pthread_join(last_thread, NULL);
pthread_mutex_destroy(&my_mutex); //won't happen
return 0;
}
next prev parent reply other threads:[~2014-05-14 7:37 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-13 3:34 [ISSUE] sched/cgroup: Does cpu-cgroup still works fine nowadays? Michael wang
2014-05-13 9:47 ` Peter Zijlstra
2014-05-13 13:36 ` Rik van Riel
2014-05-13 14:23 ` Peter Zijlstra
2014-05-14 3:27 ` Michael wang
2014-05-14 7:36 ` Michael wang [this message]
2014-05-14 9:44 ` Peter Zijlstra
2014-05-15 3:46 ` Michael wang
2014-05-15 8:35 ` Peter Zijlstra
2014-05-15 8:46 ` Michael wang
2014-05-15 9:06 ` Peter Zijlstra
2014-05-15 9:35 ` Michael wang
2014-05-15 11:57 ` Peter Zijlstra
2014-05-16 2:23 ` Michael wang
2014-05-16 2:51 ` Mike Galbraith
2014-05-16 4:24 ` Michael wang
2014-05-16 7:54 ` Peter Zijlstra
2014-05-16 8:15 ` Michael wang
2014-06-10 8:56 ` Michael wang
2014-06-10 12:12 ` Peter Zijlstra
2014-06-11 6:13 ` Michael wang
2014-06-11 8:24 ` Peter Zijlstra
2014-06-11 9:18 ` Michael wang
2014-06-23 9:42 ` Peter Zijlstra
2014-06-24 3:10 ` Michael wang
2014-05-16 7:48 ` Peter Zijlstra
2014-05-14 3:21 ` Michael wang
2014-05-14 3:16 ` Michael wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53731D12.7040804@linux.vnet.ibm.com \
--to=wangyun@linux.vnet.ibm.com \
--cc=alex.shi@linaro.org \
--cc=daniel.lezcano@linaro.org \
--cc=efault@gmx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=riel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).