From: Ken Steele Date: Fri, 20 Jun 2014 18:53:16 +0000 (-0400) Subject: Rework Tile CPU affinity setting to handle non-contiguous sets of CPUs. X-Git-Tag: suricata-2.0.2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6ebc20f6d823fb0c2f349ba56b7784d9cf87b54a;p=thirdparty%2Fsuricata.git Rework Tile CPU affinity setting to handle non-contiguous sets of CPUs. It is possible to have a non-contiguous CPU set, which was not being handled correctly on the TILE architecture. Added a "rank" field in the ThreadVar to store the worker's rank separately from the cpu for this case. --- diff --git a/src/runmode-tile.c b/src/runmode-tile.c index 46e115da8c..9e12fd9e85 100644 --- a/src/runmode-tile.c +++ b/src/runmode-tile.c @@ -194,6 +194,16 @@ int RunModeTileMpipeWorkers(DetectEngineCtx *de_ctx) } } + /* Get affinity for worker */ + cpu_set_t cpus; + //int result = tmc_cpus_get_my_affinity(&cpus); + int result = tmc_cpus_get_dataplane_cpus(&cpus); + if (result < 0) { + SCLogError(SC_ERR_INVALID_ARGUMENT, + "tmc_cpus_get_my_affinity() returned=%d", result); + SCReturnInt(TM_ECODE_FAILED); + } + for (pipe = 0; pipe < tile_num_pipelines; pipe++) { char *mpipe_devc; @@ -231,8 +241,10 @@ int RunModeTileMpipeWorkers(DetectEngineCtx *de_ctx) } TmSlotSetFuncAppend(tv_worker, tm_module, (void *)mpipe_devc); - /* set affinity for worker */ - int pipe_cpu = pipe + 1; + /* Bind to a single cpu. */ + int pipe_cpu = tmc_cpus_find_nth_cpu(&cpus, pipe); + tv_worker->rank = pipe; + TmThreadSetCPUAffinity(tv_worker, pipe_cpu); tm_module = TmModuleGetByName("DecodeMpipe"); diff --git a/src/source-mpipe.c b/src/source-mpipe.c index 0574f18007..675882efff 100644 --- a/src/source-mpipe.c +++ b/src/source-mpipe.c @@ -331,7 +331,7 @@ TmEcode ReceiveMpipeLoop(ThreadVars *tv, void *data, void *slot) ptv->slot = s->slot_next; Packet *p = NULL; int cpu = tmc_cpus_get_my_cpu(); - int rank = cpu - 1; + int rank = tv->rank; int max_queued = 0; char *ctype; @@ -875,8 +875,7 @@ static int MpipeReceiveOpenEgress(char *out_iface, int iface_idx, TmEcode ReceiveMpipeThreadInit(ThreadVars *tv, void *initdata, void **data) { SCEnter(); - int cpu = tmc_cpus_get_my_cpu(); - int rank = (cpu-1); // FIXME: Assumes worker CPUs start at 1. + int rank = tv->rank; int num_buckets = 4096; int num_workers = tile_num_pipelines; @@ -896,13 +895,6 @@ TmEcode ReceiveMpipeThreadInit(ThreadVars *tv, void *initdata, void **data) int result; char *link_name = (char *)initdata; - /* Bind to a single cpu. */ - cpu_set_t cpus; - result = tmc_cpus_get_my_affinity(&cpus); - VERIFY(result, "tmc_cpus_get_my_affinity()"); - result = tmc_cpus_set_my_cpu(tmc_cpus_find_first_cpu(&cpus)); - VERIFY(result, "tmc_cpus_set_my_cpu()"); - MpipeRegisterPerfCounters(ptv, tv); *data = (void *)ptv; diff --git a/src/threadvars.h b/src/threadvars.h index 6502072b90..0e04af2ca9 100644 --- a/src/threadvars.h +++ b/src/threadvars.h @@ -93,6 +93,7 @@ typedef struct ThreadVars_ { uint8_t type; uint16_t cpu_affinity; /** cpu or core number to set affinity to */ + uint16_t rank; int thread_priority; /** priority (real time) for this thread. Look at threads.h */ /* the perf counter context and the perf counter array */