@@ -1044,8 +1044,13 @@ static unsigned int is_cpumask_zero(const struct bitmask *mask)
static int cpu_for_thread_sp(int thread_num, int max_cpus)
{
unsigned int m, cpu, i, num_cpus;
+
num_cpus = rt_numa_bitmask_count(affinity_mask);
+ if (num_cpus == 0) {
+ fatal("No allowable cpus to run on\n");
+ }
+
m = thread_num % num_cpus;
/* there are num_cpus bits set, we want position of m'th one */
@@ -1091,6 +1096,30 @@ static int cpu_for_thread_ua(int thread_num, int max_cpus)
}
+/* After this function is called, affinity_mask is the intersection of the user
+ * supplied affinity mask and the affinity mask from the run time environment */
+static void use_current_cpuset(const int max_cpus)
+{
+ int i;
+ pid_t pid;
+ struct bitmask *curmask;
+
+ pid = getpid();
+
+ curmask = numa_bitmask_alloc(sizeof(struct bitmask));
+ numa_sched_getaffinity(pid, curmask);
+
+ /* Clear bits that are not set in both the cpuset from the environment,
+ * and in the user specified affinity for cyclictest */
+ for (i=0; i < max_cpus; i++) {
+ if ((!rt_numa_bitmask_isbitset(affinity_mask, i)) || (!rt_numa_bitmask_isbitset(curmask, i))) {
+ numa_bitmask_clearbit(affinity_mask, i);
+ }
+ }
+
+ numa_bitmask_free(curmask);
+}
+
static void parse_cpumask(const char *option, const int max_cpus)
{
affinity_mask = rt_numa_parse_cpustring(option, max_cpus);
@@ -1098,7 +1127,10 @@ static void parse_cpumask(const char *option, const int max_cpus)
if (is_cpumask_zero(affinity_mask)) {
rt_bitmask_free(affinity_mask);
affinity_mask = NULL;
+ } else {
+ use_current_cpuset(max_cpus);
}
+
}
if (!affinity_mask)
display_help(1);
Currently if the user passes the affinity to cyclictest, threads are run there even if they should be excluded according to the affinity of the runtime environment. For example taskset -c 4-7 cyclictest -t -a 1-6 Should run on the interesection of this, that is on cpus 4,5,6 Fix this so it works as expected Note, one caveat, this apply to the threads that cyclictest creates, but only the initial taskset applies to the main cyclictest thread, so the main thread can run on cpus 4,5,6 and 7 Signed-off-by: John Kacur <jkacur@redhat.com> --- src/cyclictest/cyclictest.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)