From 18e9e3338d64d4b1b7b611e8e4c5e814b14058ae Mon Sep 17 00:00:00 2001 From: Patrick Lu Date: Tue, 16 Oct 2018 21:49:17 -0700 Subject: jitter: add a new option to pin core Instead of use taskset, we introduce -c to set thread affinity directly in the program itself. Change-Id: Ibac6143b6581b3186a953c6931da12f854d087c0 Signed-off-by: Patrick Lu --- jitter/jitter.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/jitter/jitter.c b/jitter/jitter.c index 2116bda..a93929e 100644 --- a/jitter/jitter.c +++ b/jitter/jitter.c @@ -43,6 +43,10 @@ #include #include #include +#define __USE_GNU +#include + +#define DEFAULT_CORE 1 union timestampclock { @@ -129,8 +133,9 @@ void signalHandler(int signalno) void showhelp() { printf("usage:\n"); - printf("taskset -c ./jitter [-l] [r] [-h] [-p $(pgrep perf)] [-t]\n"); + printf("./jitter [-c ] [-l] [r] [-h] [-p $(pgrep perf)] [-t]\n"); + printf(" -c : pin jitter to core_id. Default core_id is %d\n", DEFAULT_CORE); printf(" -r : Display update rate. Default is %d\n", displayUpdate); printf(" -l : Loop count for code block. Default is %d\n", loopcount); printf(" -p : perf_pid [run: perf record -S -C$CORENO -e intel_pt// -v on another window]\n"); @@ -167,17 +172,21 @@ int main(int argc, char* argv[]) uint64_t absoluteMin=MINVAL, absoluteMax=0, TransientMax=0, TransientMin=MINVAL; unsigned int tmp=0; int userinput; + uint32_t core_id = DEFAULT_CORE; + cpu_set_t cpuset; #ifdef PROCESSOR_TRACE pid_t perf_pid = -1; int skip = 5, signaled = 0; #endif - printf("Linux Jitter testing program version 1.8\n"); + printf("Linux Jitter testing program version 1.9\n"); - while ((userinput = getopt(argc, argv, "l:r:hp:t:i:")) != EOF) + while ((userinput = getopt(argc, argv, "c:l:r:hp:t:i:")) != EOF) { switch(userinput) { + case 'c' : core_id = strtoul(optarg, (char**)NULL, 0); + break; case 'h' : showhelp(); exit(0); case 'l' : loopcount = strtoul(optarg, (char**)NULL, 0); @@ -211,6 +220,7 @@ int main(int argc, char* argv[]) printf("The pragram will execute a dummy function %u times\n",loopcount); printf("Display is updated every %u displayUpdate intervals\n",displayUpdate); + printf("Thread affinity will be set to core_id:%u\n", core_id); displayInfo(); @@ -221,6 +231,11 @@ int main(int argc, char* argv[]) } + // set Thread affinity + CPU_ZERO(&cpuset); + CPU_SET(core_id, &cpuset); + sched_setaffinity(0, sizeof(cpuset), &cpuset); + printf("%s",title); seedtime = TimeStampCounter(); // get a random value from timestamp -- cgit 1.2.3-korg