Changeset 773d5e2


Ignore:
Timestamp:
03/24/15 12:54:51 (6 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
e0be8382
Parents:
6b98325
Message:

Fix some portability issues we'll run into with non-portable pthread functions.

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/format_dpdk.c

    r6b98325 r773d5e2  
    163163#include <rte_cycles.h>
    164164#include <pthread.h>
     165#ifdef __FreeBSD__
     166#include <pthread_np.h>
     167#endif
     168
    165169
    166170/* The default size of memory buffers to use - This is the max size of standard
  • lib/trace_parallel.c

    r6b98325 r773d5e2  
    119119static void print_memory_stats() {
    120120#if 0
     121        uint64_t total;
     122#ifdef __linux__
    121123        char t_name[50];
    122         uint64_t total;
    123124        pthread_getname_np(pthread_self(), t_name, sizeof(t_name));
    124125
    125126        fprintf(stderr, "Thread ID#%d - %s\n", (int) pthread_self(), t_name);
     127#else
     128        fprintf(stderr, "Thread ID#%d\n", (int) pthread_self());
     129#endif
    126130
    127131        total = mem_hits.read.cache_hit + mem_hits.read.ring_hit + mem_hits.read.miss;
     
    165169/*
    166170 * This can be used once the hasher thread has been started and internally after
    167  * verfiy_configuration.
     171 * verify_configuration.
    168172 */
    169173DLLEXPORT bool trace_has_dedicated_hasher(libtrace_t * libtrace)
     
    13471351 */
    13481352SIMPLE_FUNCTION static int get_nb_cores() {
    1349         // TODO add BSD support
    1350         return sysconf(_SC_NPROCESSORS_ONLN);
     1353        int numCPU;
     1354#ifdef _SC_NPROCESSORS_ONLN
     1355        /* Most systems do this now */
     1356        numCPU = sysconf(_SC_NPROCESSORS_ONLN);
     1357
     1358#else
     1359        int mib[] = {CTL_HW, HW_AVAILCPU};
     1360        size_t len = sizeof(numCPU);
     1361
     1362        /* get the number of CPUs from the system */
     1363        sysctl(mib, 2, &numCPU, &len, NULL, 0);
     1364#endif
     1365        return numCPU <= 0 ? 1 : numCPU;
    13511366}
    13521367
     
    14121427                       int perpkt_num,
    14131428                       const char *name) {
     1429#ifdef __linux__
    14141430        pthread_attr_t attrib;
    14151431        cpu_set_t cpus;
     1432#endif
    14161433        int ret, i;
    14171434        assert(t->type == THREAD_EMPTY);
     
    14221439        t->state = THREAD_RUNNING;
    14231440
     1441#ifdef __linux__
    14241442        CPU_ZERO(&cpus);
    14251443        for (i = 0; i < get_nb_cores(); i++)
     
    14271445        pthread_attr_init(&attrib);
    14281446        pthread_attr_setaffinity_np(&attrib, sizeof(cpus), &cpus);
    1429 
    14301447        ret = pthread_create(&t->tid, &attrib, start_routine, (void *) trace);
    14311448        pthread_attr_destroy(&attrib);
     1449#else
     1450        ret = pthread_create(&t->tid, NULL, start_routine, (void *) trace);
     1451#endif
    14321452        if (ret != 0) {
    14331453                libtrace_zero_thread(t);
     
    14431463                                                 LIBTRACE_RINGBUFFER_BLOCKING);
    14441464        }
     1465#ifdef __linux__
    14451466        if(name)
    14461467                pthread_setname_np(t->tid, name);
     1468#endif
    14471469        t->perpkt_num = perpkt_num;
    14481470        return 0;
Note: See TracChangeset for help on using the changeset viewer.