aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Mason <clm@fb.com>2021-04-19 15:55:34 -0700
committerChris Mason <clm@fb.com>2021-04-19 15:55:34 -0700
commit017c516570ac0a2e02c4dfcd541f58deddc7cddb (patch)
treefe9e7d9b4a6298122fac429b2dbb33704b979cbd
parent3dc293f780fb4b2a5216a0bf83633a050d36c8f6 (diff)
downloadschbench-017c516570ac0a2e02c4dfcd541f58deddc7cddb.tar.gz
schbench: add jitter to CPU time with -j
Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r--schbench.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/schbench.c b/schbench.c
index f579a6e..ca035cf 100644
--- a/schbench.c
+++ b/schbench.c
@@ -53,6 +53,8 @@ static int zerotime = 0;
static unsigned long long cputime = 30000;
/* -a, bool */
static int autobench = 0;
+/* -j jitter bool */
+static int jitter = 0;
/* -A, int percentage busy */
static int auto_rps = 0;
/* -p bytes */
@@ -86,9 +88,10 @@ enum {
HELP_LONG_OPT = 1,
};
-char *option_string = "p:am:t:s:c:C:r:R:w:i:z:A:";
+char *option_string = "p:am:t:s:c:C:r:R:w:i:z:A:j";
static struct option long_options[] = {
{"auto", no_argument, 0, 'a'},
+ {"jitter", no_argument, 0, 'a'},
{"pipe", required_argument, 0, 'p'},
{"message-threads", required_argument, 0, 'm'},
{"threads", required_argument, 0, 't'},
@@ -115,6 +118,7 @@ static void print_usage(void)
"\t-C (--message_cputime): Message thread think time (usec, def: 30000\n"
"\t-c (--cputime): How long to think during loop (usec, def: 30000\n"
"\t-a (--auto): grow thread count until latencies hurt (def: off)\n"
+ "\t-j (--jitter): add jitter to sleep/cputimes (def: off)\n"
"\t-A (--auto-rps): grow RPS until cpu utilization hits target (def: none)\n"
"\t-p (--pipe): transfer size bytes to simulate a pipe test (def: 0)\n"
"\t-R (--rps): requests per second mode (count, def: 0)\n"
@@ -147,6 +151,9 @@ static void parse_options(int ac, char **av)
autobench = 1;
warmuptime = 0;
break;
+ case 'j':
+ jitter = 1;
+ break;
case 'A':
auto_rps = atoi(optarg);
warmuptime = 0;
@@ -805,6 +812,12 @@ static void usec_spin(unsigned long spin_time)
if (spin_time == 0)
return;
+ if (jitter) {
+ unsigned int seed = pthread_self();
+ unsigned long new_time = rand_r(&seed) % spin_time;
+ spin_time = new_time + 1;
+ }
+
gettimeofday(&start, NULL);
while (1) {
gettimeofday(&now, NULL);