Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/6927 add unit tests v2 #10838

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions src/runmode-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,51 @@ static void ConfigSetIface(DPDKIfaceConfig *iconf, const char *entry_str)
SCReturn;
}

static int32_t remaining_auto_cpus = -1;
/**
* Initialize the number of remaining auto-assigned threads
* \param total_cpus Total number of CPU cores available
* \param force_reinit Force reinitialization of the remaining threads after auto-assign
*/
static void AutoRemainingThreadsInit(bool force_reinit)
{
if (remaining_auto_cpus == -1 || force_reinit) {
ThreadsAffinityType *wtaf = GetAffinityTypeFromName("worker-cpu-set");
if (wtaf == NULL)
FatalError("Worker-cpu-set not listed in the threading section");

int32_t total_cpus = UtilAffinityGetAffinedCPUNum(wtaf);
if (total_cpus == 0)
FatalError("No worker CPU cores with affinity were configured");

int32_t ldevs = LiveGetDeviceCount();
if (ldevs == 0)
FatalError("No devices configured");
remaining_auto_cpus = total_cpus % ldevs;
}
}

/**
* Decrease the number of remaining auto-assigned threads by one
* \return Remaining number of the auto-assigned leftover threads
*/
static bool AutoRemainingThreadsUsedOne(void)
{
if (remaining_auto_cpus == -1) {
FatalError("Not yet initialized");
}

if (remaining_auto_cpus > 0) {
remaining_auto_cpus--;
return true;
}

return false;
}

static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str)
{
SCEnter();
static int32_t remaining_auto_cpus = -1;
if (!threading_set_cpu_affinity) {
SCLogError("DPDK runmode requires configured thread affinity");
SCReturnInt(-EINVAL);
Expand Down Expand Up @@ -411,15 +452,9 @@ static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str)
SCReturnInt(-ERANGE);
}

if (remaining_auto_cpus > 0) {
AutoRemainingThreadsInit(false);
if (AutoRemainingThreadsUsedOne()) {
iconf->threads++;
remaining_auto_cpus--;
} else if (remaining_auto_cpus == -1) {
remaining_auto_cpus = (int32_t)sched_cpus % LiveGetDeviceCount();
if (remaining_auto_cpus > 0) {
iconf->threads++;
remaining_auto_cpus--;
}
}
SCLogConfig("%s: auto-assigned %u threads", iconf->iface, iconf->threads);
SCReturnInt(0);
Expand Down
9 changes: 6 additions & 3 deletions src/util-affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,15 @@ uint16_t UtilAffinityCpusOverlap(ThreadsAffinityType *taf1, ThreadsAffinityType
*/
void UtilAffinityCpusExclude(ThreadsAffinityType *mod_taf, ThreadsAffinityType *static_taf)
{
cpu_set_t tmpset;
SCMutexLock(&mod_taf->taf_mutex);
SCMutexLock(&static_taf->taf_mutex);
CPU_XOR(&tmpset, &mod_taf->cpu_set, &static_taf->cpu_set);
int max_cpus = UtilCpuGetNumProcessorsOnline();
for (int cpu = 0; cpu < max_cpus; cpu++) {
if (CPU_ISSET(cpu, &mod_taf->cpu_set) && CPU_ISSET(cpu, &static_taf->cpu_set)) {
CPU_CLR(cpu, &mod_taf->cpu_set);
}
}
SCMutexUnlock(&static_taf->taf_mutex);
mod_taf->cpu_set = tmpset;
SCMutexUnlock(&mod_taf->taf_mutex);
}
#endif /* HAVE_DPDK */
3 changes: 3 additions & 0 deletions src/util-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ int LiveDeviceListClean(void)
SCFree(pd);
}

TAILQ_INIT(&live_devices); // reset the list
SCReturnInt(TM_ECODE_OK);
}

Expand Down Expand Up @@ -451,6 +452,8 @@ void LiveDeviceFinalize(void)
}
SCFree(ld);
}

TAILQ_INIT(&pre_live_devices); // reset the list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it not be done in a separate "reset" function ?

Looks strange to see SomeFuncFinalize end with INIT

}

static void LiveDevExtensionFree(void *x)
Expand Down