Skip to content

Commit

Permalink
runmodes: fix 'threads' option parsing
Browse files Browse the repository at this point in the history
Don't cast int to uint8_t for no reason. Add warning that upper
limit for theads is 1024.

Small code cleanups.

Bug: #2243
  • Loading branch information
victorjulien committed Oct 17, 2017
1 parent aab2548 commit 2b3d960
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/runmode-af-packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void *ParseAFPConfig(const char *iface)
if (strcmp(threadsstr, "auto") == 0) {
aconf->threads = 0;
} else {
aconf->threads = (uint8_t)atoi(threadsstr);
aconf->threads = atoi(threadsstr);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/runmode-netmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static int ParseNetmapSettings(NetmapIfaceSettings *ns, const char *iface,
if (strcmp(threadsstr, "auto") == 0) {
ns->threads = 0;
} else {
ns->threads = (uint8_t)atoi(threadsstr);
ns->threads = atoi(threadsstr);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/runmode-pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void *ParsePcapConfig(const char *iface)
aconf->threads = 1;
} else {
if (threadsstr != NULL) {
aconf->threads = (uint8_t)atoi(threadsstr);
aconf->threads = atoi(threadsstr);
}
}
if (aconf->threads == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/runmode-pfring.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void *OldParsePfringConfig(const char *iface)
pfconf->threads = 1;
} else {
if (threadsstr != NULL) {
pfconf->threads = (uint8_t)atoi(threadsstr);
pfconf->threads = atoi(threadsstr);
}
}
if (pfconf->threads == 0) {
Expand Down Expand Up @@ -252,7 +252,7 @@ void *ParsePfringConfig(const char *iface)
pfconf->threads = 1;
} else {
if (threadsstr != NULL) {
pfconf->threads = (uint8_t)atoi(threadsstr);
pfconf->threads = atoi(threadsstr);
}
}
if (pfconf->threads == 0) {
Expand Down
28 changes: 14 additions & 14 deletions src/util-runmodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
char tname[TM_THREAD_NAME_MAX];
char qname[TM_QUEUE_NAME_MAX];
char *queues = NULL;
uint16_t thread = 0;

/* Available cpus */
uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
Expand All @@ -106,8 +105,10 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
thread_max = ncpus * threading_detect_ratio;
if (thread_max < 1)
thread_max = 1;
if (thread_max > 1024)
if (thread_max > 1024) {
SCLogWarning(SC_ERR_RUNMODE, "limited number of 'worker' threads to 1024. Wanted %d", thread_max);
thread_max = 1024;
}

queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
if (queues == NULL) {
Expand All @@ -123,8 +124,8 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,

aconf = ConfigParser(live_dev);
if (aconf == NULL) {
SCLogError(SC_ERR_RUNMODE, "Failed to allocate config for %s (%d)",
live_dev, thread);
SCLogError(SC_ERR_RUNMODE, "Failed to allocate config for %s",
live_dev);
exit(EXIT_FAILURE);
}

Expand All @@ -133,7 +134,7 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
threads_count, recv_mod_name);

/* create the threads */
for (thread = 0; thread < threads_count; thread++) {
for (int thread = 0; thread < MIN(thread_max, threads_count); thread++) {
snprintf(tname, sizeof(tname), "%s#%02d", thread_name, thread+1);
ThreadVars *tv_receive =
TmThreadCreatePacketHandler(tname,
Expand Down Expand Up @@ -169,9 +170,8 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
}
} else { /* Multiple input device */
SCLogInfo("Using %d live device(s).", nlive);
int lthread;

for (lthread = 0; lthread < nlive; lthread++) {
for (int lthread = 0; lthread < nlive; lthread++) {
const char *dev = LiveGetDeviceName(lthread);
const char *visual_devname = LiveGetShortName(live_dev);
void *aconf;
Expand All @@ -191,7 +191,7 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
}

threads_count = ModThreadsCount(aconf);
for (thread = 0; thread < threads_count; thread++) {
for (int thread = 0; thread < threads_count; thread++) {
snprintf(tname, sizeof(tname), "%s#%02d-%s", thread_name,
thread+1, visual_devname);

Expand Down Expand Up @@ -227,7 +227,7 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
}
}

for (thread = 0; thread < (uint16_t)thread_max; thread++) {
for (int thread = 0; thread < thread_max; thread++) {
snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
snprintf(qname, sizeof(qname), "pickup%u", thread+1);

Expand Down Expand Up @@ -278,7 +278,6 @@ static int RunModeSetLiveCaptureWorkersForDevice(ConfigIfaceThreadsCountFunc Mod
const char *live_dev, void *aconf,
unsigned char single_mode)
{
int thread;
int threads_count;

if (single_mode) {
Expand All @@ -289,7 +288,7 @@ static int RunModeSetLiveCaptureWorkersForDevice(ConfigIfaceThreadsCountFunc Mod
}

/* create the threads */
for (thread = 0; thread < threads_count; thread++) {
for (int thread = 0; thread < threads_count; thread++) {
char tname[TM_THREAD_NAME_MAX];
ThreadVars *tv = NULL;
TmModule *tm_module = NULL;
Expand Down Expand Up @@ -433,7 +432,6 @@ int RunModeSetIPSAutoFp(ConfigIPSParserFunc ConfigParser,
TmModule *tm_module ;
const char *cur_queue = NULL;
char *queues = NULL;
uint16_t thread;

/* Available cpus */
uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
Expand All @@ -445,8 +443,10 @@ int RunModeSetIPSAutoFp(ConfigIPSParserFunc ConfigParser,
thread_max = ncpus * threading_detect_ratio;
if (thread_max < 1)
thread_max = 1;
if (thread_max > 1024)
if (thread_max > 1024) {
SCLogWarning(SC_ERR_RUNMODE, "limited number of 'worker' threads to 1024. Wanted %d", thread_max);
thread_max = 1024;
}

queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
if (queues == NULL) {
Expand Down Expand Up @@ -494,7 +494,7 @@ int RunModeSetIPSAutoFp(ConfigIPSParserFunc ConfigParser,
}

}
for (thread = 0; thread < (uint16_t)thread_max; thread++) {
for (int thread = 0; thread < thread_max; thread++) {
snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
snprintf(qname, sizeof(qname), "pickup%u", thread+1);

Expand Down

0 comments on commit 2b3d960

Please sign in to comment.