- Timestamp:
- 03/18/15 16:31:49 (6 years ago)
- 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:
- 963b13b
- Parents:
- 6c84681
- Location:
- lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_dpdk.c
re3d534f r1407294 879 879 toeplitz_create_bikey(FORMAT(libtrace)->rss_key); 880 880 return 0; 881 case HASHER_HARDWARE:882 881 case HASHER_CUSTOM: 883 882 // We don't support these -
lib/format_linux_common.c
ra978dec r1407294 527 527 return 0; 528 528 case HASHER_CUSTOM: 529 case HASHER_HARDWARE:530 529 return -1; 531 530 } -
lib/libtrace_parallel.h
r6a6e6a8 r1407294 284 284 }; 285 285 286 /** The hasher types avaliable to libtrace application. 287 * These can be selected using trace_set_hasher(). 288 */ 286 289 enum hasher_types { 287 /** 288 * Balance load across CPUs best as possible, this is basically to say do289 * not care about hash. This might still might be implemented290 * using a hash or round robin etc. under the hood depending on the format290 /** Balance load across per-packet threads as best as possible, this is 291 * basically to say I do not care about where packets are sent. This 292 * might still might be implemented using a hash or round robin etc. 293 * depending on the format and libtrace configuration. 291 294 */ 292 295 HASHER_BALANCE, 293 296 294 /** Use a hash which is bi-directional for TCP flows, that is packets with 295 * the same hash are sent to the same thread. All non TCP packets will be 296 * sent to the same thread. UDP may or may not be sent to separate 297 * threads like TCP, this depends on the format support. 297 /** Use a hash which is bi-directional for TCP and UDP flows, that is 298 * packets with the same 5-tuple are sent to the same per-packet thread. 299 * All non TCP/UDP packets will be sent to the same thread. 300 * 301 * @note it is possible that UDP packets may not be spread across 302 * per-packet threads, depending upon the format support. In this case 303 * they would be directed to a single per-packet thread. 298 304 */ 299 305 HASHER_BIDIRECTIONAL, 300 306 301 /** 302 * Use a hash which is uni-directional across TCP flows, that means the303 * opposite directions of the same 5 tuple might end up on separate cores.304 * Otherwise is identical to HASHER_BIDIRECTIONAL307 /** Use a hash which is uni-directional across TCP and UDP flows, this 308 * means the opposing directions of the same 5-tuple might end up on 309 * different per-packet threads. 310 * Otherwise this is identical to HASHER_BIDIRECTIONAL 305 311 */ 306 312 HASHER_UNIDIRECTIONAL, 307 313 308 314 /** 309 * Always use the user supplied hasher, this currently disables native 310 * support and is likely significantly slower. 311 */ 312 HASHER_CUSTOM, 313 314 /** 315 * This is not a valid option, used internally only!!! TODO remove 316 * Set by the format if the hashing is going to be done in hardware 317 */ 318 HASHER_HARDWARE 315 * Always use the user supplied hasher, this disables native 316 * support in and is likely significantly slower. 317 */ 318 HASHER_CUSTOM 319 319 }; 320 320 … … 676 676 /// @} 677 677 678 679 /** TODO DOXS 678 /** Set the hasher function for a parallel trace. 679 * 680 * @param[in] trace The parallel trace to apply the hasher to 681 * @param[in] type The type of hashing to apply, see enum hasher_types 682 * @param[in] hasher A hasher function to use [Optional] 683 * @param[in] data Data passed to the hasher function [Optional] 684 * 685 * @return 0 if successful otherwise -1 on error 686 * 687 * The hasher function in a parallel trace can be used to control which 688 * per-packet thread a packets is processed by. 689 * 690 * HASHER_BALANCE is the default and will dispatch packets as fast as possible 691 * to all threads arbitrarily. As such when called the hasher and 692 * data parameters must be set to NULL. 693 * 694 * HASHER_CUSTOM will force the libtrace to use the user defined function. As 695 * such the hasher parameter must be supplied. 696 * 697 * With other defined hasher types we will try to push the hashing into the format 698 * by default. In this case the hasher parameter is optional and will be 699 * preferred over the default supplied by libtrace. 700 * 701 * @note When supplying a hasher function it should be thread-safe as it could 702 * be run in parallel by libtrace. Ideally this should rely upon no state, other 703 * than some form of seed value supplied in data. 680 704 */ 681 705 DLLEXPORT int trace_set_hasher(libtrace_t *trace, enum hasher_types type, fn_hasher hasher, void *data); … … 685 709 * as such making use of built-in types is important. 686 710 * 687 * User specific results should be defined as values greater than RESULT_USER(1000)711 * Custom result types users should be defined as RESULT_USER(1000) or greater. 688 712 * 689 713 */ … … 731 755 int type); 732 756 733 /** Check if a dedicated hasher thread is being used 757 /** Check if a dedicated hasher thread is being used. 734 758 * 735 759 * @return True if the trace has dedicated hasher thread otherwise false. 760 * 761 * This is valid once the trace is running after calling trace_pstart(). 736 762 */ 737 763 DLLEXPORT bool trace_has_dedicated_hasher(libtrace_t * libtrace); -
lib/trace_parallel.c
r6a6e6a8 r1407294 657 657 658 658 pthread_exit(NULL); 659 } ;659 } 660 660 661 661 /** … … 1314 1314 1315 1315 /** 1316 * @return the number of CPU cores on the machine. -1 if unknown. 1317 */ 1318 SIMPLE_FUNCTION static int get_nb_cores() { 1319 // TODO add BSD support 1320 return sysconf(_SC_NPROCESSORS_ONLN); 1321 } 1322 1323 /** 1316 1324 * Verifies the configuration and sets default values for any values not 1317 1325 * specified by the user. 1318 1326 */ 1319 1327 static void verify_configuration(libtrace_t *libtrace) { 1320 bool require_hasher = false;1321 1322 /* Might we need a dedicated hasher thread? */1323 if (libtrace->hasher && libtrace->hasher_type != HASHER_HARDWARE) {1324 require_hasher = true;1325 }1326 1328 1327 1329 if (libtrace->config.hasher_queue_size <= 0) … … 1329 1331 1330 1332 if (libtrace->config.perpkt_threads <= 0) { 1331 // TODO add BSD support 1332 libtrace->perpkt_thread_count = sysconf(_SC_NPROCESSORS_ONLN); 1333 libtrace->perpkt_thread_count = get_nb_cores(); 1333 1334 if (libtrace->perpkt_thread_count <= 0) 1334 1335 // Lets just use one … … 1354 1355 libtrace->combiner = combiner_unordered; 1355 1356 1356 1357 1357 /* Figure out if we are using a dedicated hasher thread? */ 1358 if ( require_hasher && libtrace->perpkt_thread_count > 1) {1358 if (libtrace->hasher && libtrace->perpkt_thread_count > 1) { 1359 1359 libtrace->hasher_thread.type = THREAD_HASHER; 1360 1360 } … … 1382 1382 int perpkt_num, 1383 1383 const char *name) { 1384 int ret; 1384 pthread_attr_t attrib; 1385 cpu_set_t cpus; 1386 int ret, i; 1385 1387 assert(t->type == THREAD_EMPTY); 1386 1388 t->trace = trace; … … 1389 1391 t->type = type; 1390 1392 t->state = THREAD_RUNNING; 1391 ret = pthread_create(&t->tid, NULL, start_routine, (void *) trace); 1393 1394 CPU_ZERO(&cpus); 1395 for (i = 0; i < get_nb_cores(); i++) 1396 CPU_SET(i, &cpus); 1397 pthread_attr_init(&attrib); 1398 pthread_attr_setaffinity_np(&attrib, sizeof(cpus), &cpus); 1399 1400 ret = pthread_create(&t->tid, &attrib, start_routine, (void *) trace); 1401 pthread_attr_destroy(&attrib); 1392 1402 if (ret != 0) { 1393 1403 libtrace_zero_thread(t); 1394 trace_set_err(trace, ret, "Failed to create a thread ");1404 trace_set_err(trace, ret, "Failed to create a thread of type=%d\n", type); 1395 1405 return -1; 1396 1406 } … … 1568 1578 THREAD_HASHER, hasher_entry, -1, 1569 1579 "hasher-thread"); 1570 if (ret != 0) { 1571 trace_set_err(libtrace, errno, "trace_pstart " 1572 "failed to start a hasher thread."); 1580 if (ret != 0) 1573 1581 goto cleanup_started; 1574 }1575 1582 libtrace->pread = trace_pread_packet_hasher_thread; 1576 1583 } else { … … 1592 1599 THREAD_PERPKT, perpkt_threads_entry, i, 1593 1600 name); 1594 if (ret != 0) { 1595 trace_set_err(libtrace, errno, "trace_pstart " 1596 "failed to start a perpkt thread."); 1601 if (ret != 0) 1597 1602 goto cleanup_threads; 1598 }1599 1603 } 1600 1604 … … 1606 1610 THREAD_REPORTER, reporter_entry, -1, 1607 1611 "reporter_thread"); 1608 if (ret != 0) { 1609 trace_set_err(libtrace, errno, "trace_pstart " 1610 "failed to start reporter thread."); 1612 if (ret != 0) 1611 1613 goto cleanup_threads; 1612 }1613 1614 } 1614 1615 … … 1618 1619 THREAD_KEEPALIVE, keepalive_entry, -1, 1619 1620 "keepalive_thread"); 1620 if (ret != 0) { 1621 trace_set_err(libtrace, errno, "trace_pstart " 1622 "failed to start keepalive thread."); 1621 if (ret != 0) 1623 1622 goto cleanup_threads; 1624 }1625 1623 } 1626 1624 … … 1760 1758 libtrace_message_t message = {0}; 1761 1759 message.code = MESSAGE_DO_PAUSE; 1762 trace_message_thread(libtrace, &libtrace->perpkt_threads[i], &message);1760 ASSERT_RET(trace_message_thread(libtrace, &libtrace->perpkt_threads[i], &message), != -1); 1763 1761 if(trace_has_dedicated_hasher(libtrace)) { 1764 1762 // The hasher has stopped and other threads have messages waiting therefore … … 1870 1868 } 1871 1869 1872 /**1873 * Set the hasher type along with a selected function, if hardware supports1874 * that generic type of hashing it will be used otherwise the supplied1875 * hasher function will be used and passed data when called.1876 *1877 * @return 0 if successful otherwise -1 on error1878 */1879 1870 DLLEXPORT int trace_set_hasher(libtrace_t *trace, enum hasher_types type, fn_hasher hasher, void *data) { 1880 1871 int ret = -1; 1881 if ( type == HASHER_HARDWARE ||(type == HASHER_CUSTOM && !hasher) || (type == HASHER_BALANCE && hasher)) {1872 if ((type == HASHER_CUSTOM && !hasher) || (type == HASHER_BALANCE && hasher)) { 1882 1873 return -1; 1883 1874 } … … 1900 1891 1901 1892 if (ret == -1) { 1902 // We have to deal with this ourself 1903 // This most likely means single threaded reading of the trace 1893 /* We have to deal with this ourself */ 1904 1894 if (!hasher) { 1905 1895 switch (type) … … 1918 1908 toeplitz_init_config(trace->hasher_data, 0); 1919 1909 return 0; 1920 case HASHER_HARDWARE:1921 return -1;1922 1910 } 1923 1911 return -1; 1924 1912 } 1925 1913 } else { 1926 // The hardware is dealing with this yay 1927 trace->hasher_type = HASHER_HARDWARE; 1914 /* If the hasher is hardware we zero out the hasher and hasher 1915 * data fields - only if we need a hasher do we do this */ 1916 trace->hasher = NULL; 1917 trace->hasher_data = NULL; 1928 1918 } 1929 1919 … … 2057 2047 { 2058 2048 int i; 2059 int missed ;2049 int missed = 0; 2060 2050 if (message->sender == NULL) 2061 2051 message->sender = get_thread_descriptor(libtrace);
Note: See TracChangeset
for help on using the changeset viewer.