[Oisf-users] Detect_Thread_Ratio

Will Metcalf william.metcalf at gmail.com
Fri Aug 12 23:05:39 UTC 2011


I did leave out this piece...

src/runmodes.h:extern float threading_detect_ratio;

It is key...

mmmmm grasshopper the answer lies in the code below...

gcc -o makin-stuff makin-stuff.c
./makin-stuff

--------snip---------------
#include <stdio.h>

main(){
    int foo = 48;
    float bar = 0.2;
    int blat;

    blat = foo * bar;
    printf("where did my remainder go? %i\n", blat);

    printf("how many do we make?\n");
    int i;
    for (i = 0; i < blat; i++) {
       printf("%i\n", i +1);
    }
    return 0;
}



On Fri, Aug 12, 2011 at 5:10 PM, Gene Albin <gene.albin at gmail.com> wrote:
> Ok, so if I'm reading that right (and it's like reading
> ancient hieroglyphics to me!) it looks like first we will never have less
> than 1 thread, and second we are working with integers so no decimals.  If
> that is the case, then does the 'int' function round decimals to the nearest
> integer or does it round all down?  I don't see anything there forcing it to
> round down so I'd assume it rounds to the nearest.
> So my 'homework' answer would be that it uses integers and rounds to the
> nearest integer > 0.
> How'd I do, teach?
> Gene
> On Fri, Aug 12, 2011 at 2:59 PM, Will Metcalf <william.metcalf at gmail.com>
> wrote:
>>
>> Since this all sounds a bit like a homework assignment you tell me :D?
>>
>>   * threads we're not creating the most on CPU0. */
>>    if (ncpus > 0)
>>        cpu = 1;
>>
>>    /* always create at least one thread */
>>    int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET);
>>    if (thread_max == 0)
>>        thread_max = ncpus * threading_detect_ratio;
>>    if (thread_max < 1)
>>        thread_max = 1;
>>
>>    int thread;
>>    for (thread = 0; thread < thread_max; thread++) {
>>        snprintf(tname, sizeof(tname), "Detect%"PRIu16, thread+1);
>>
>>        char *thread_name = SCStrdup(tname);
>>        SCLogDebug("Assigning %s affinity to cpu %u", thread_name, cpu);
>>
>>        ThreadVars *tv_detect_ncpu =
>>            TmThreadCreatePacketHandler(thread_name,
>>                                        "stream-queue1", "simple",
>>                                        "alert-queue1", "simple",
>>                                        "1slot");
>>        if (tv_detect_ncpu == NULL) {
>>            printf("ERROR: TmThreadsCreate failed\n");
>>            exit(EXIT_FAILURE);
>>        }
>>        tm_module = TmModuleGetByName("Detect");
>>        if (tm_module == NULL) {
>>            printf("ERROR: TmModuleGetByName Detect failed\n");
>>            exit(EXIT_FAILURE);
>>        }
>>        Tm1SlotSetFunc(tv_detect_ncpu, tm_module, (void *)de_ctx);
>>
>>        TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET);
>>
>>        char *thread_group_name = SCStrdup("Detect");
>>        if (thread_group_name == NULL) {
>>            printf("Error allocating memory\n");
>>            exit(EXIT_FAILURE);
>>        }
>>        tv_detect_ncpu->thread_group_name = thread_group_name;
>>
>>        if (TmThreadSpawn(tv_detect_ncpu) != TM_ECODE_OK) {
>>            printf("ERROR: TmThreadSpawn failed\n");
>>            exit(EXIT_FAILURE);
>>        }
>>
>>        if ((cpu + 1) == ncpus)
>>            cpu = 0;
>>        else
>>            cpu++;
>>    }
>>
>>
>> On Fri, Aug 12, 2011 at 4:38 PM, Gene Albin <gene.albin at gmail.com> wrote:
>> > I understand that the detect_thread_ratio in the suricata.yaml file
>> > determines the number of threads created by multiplying the ratio number
>> > by
>> > the number of CPU cores.  What does Suricata do when the result is not
>> > an
>> > integer?  For example .2*48=9.6.  Is this rounded down to the lowest
>> > integer?  Does it create 9.6 threads?  Does it round up?
>> >
>> > Thanks,
>> > --
>> > Gene Albin
>> > gene.albin at gmail.com
>> >
>> >
>> > _______________________________________________
>> > Oisf-users mailing list
>> > Oisf-users at openinfosecfoundation.org
>> > http://lists.openinfosecfoundation.org/mailman/listinfo/oisf-users
>> >
>> >
>
>
>
> --
> Gene Albin
> gene.albin at gmail.com
>
>



More information about the Oisf-users mailing list