/* * Copyright (C) 2013 Davidlohr Bueso * * futex-requeue: Block a bunch of threads on futex1 and requeue them * on futex2, N at a time. * * This program is particularly useful to measure the latency of nthread * requeues without waking up any tasks -- thus mimicking a regular futex_wait. */ /* For the CLR_() macros */ #include #include #include "../util/stat.h" #include #include #include #include #include #include "bench.h" #include "futex.h" #include #include #include static u_int32_t futex1 = 0, futex2 = 0; /* * How many tasks to requeue at a time. * Default to 1 in order to make the kernel work more. */ static unsigned int nrequeue = 1; static pthread_t *worker; static bool done = false, silent = false, fshared = false; static pthread_mutex_t thread_lock; static pthread_cond_t thread_parent, thread_worker; static struct stats requeuetime_stats, requeued_stats; static unsigned int ncpus, threads_starting, nthreads = 0; static int futex_flag = 0; static const struct option options[] = { OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"), OPT_UINTEGER('q', "nrequeue", &nrequeue, "Specify amount of threads to requeue at once"), OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"), OPT_BOOLEAN( 'S', "shared", &fshared, "Use shared futexes instead of private ones"), OPT_END() }; static const char * const bench_futex_requeue_usage[] = { "perf bench futex requeue ", NULL }; static void print_summary(void) { double requeuetime_avg = avg_stats(&requeuetime_stats); double requeuetime_stddev = stddev_stats(&requeuetime_stats); unsigned int requeued_avg = avg_stats(&requeued_stats); printf("Requeued %d of %d threads in %.4f ms (+-%.2f%%)\n", requeued_avg, nthreads, requeuetime_avg / USEC_PER_MSEC, rel_stddev_stats(requeuetime_stddev, requeuetime_avg)); } static void *workerfn(void *arg __maybe_unused) { pthread_mutex_lock(&thread_lock); threads_starting--; if (!threads_starting) pthread_cond_signal(&thread_parent); pthread_cond_wait(&thread_worker, &thread_lock); pthread_mutex_unlock(&thread_lock); futex_wait(&futex1, 0, NULL, futex_flag); return NULL; } static void block_threads(pthread_t *w, pthread_attr_t thread_attr) { cpu_set_t cpu; unsigned int i; threads_starting = nthreads; /* create and block all threads */ for (i = 0; i < nthreads; i++) { CPU_ZERO(&cpu); CPU_SET(i % ncpus, &cpu); if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpu)) err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); if (pthread_create(&w[i], &thread_attr, workerfn, NULL)) err(EXIT_FAILURE, "pthread_create"); } } static void toggle_done(int sig __maybe_unused, siginfo_t *info __maybe_unused, void *uc __maybe_unused) { done = true; } int bench_futex_requeue(int argc, const char **argv, const char *prefix __maybe_unused) { int ret = 0; unsigned int i, j; struct sigaction act; pthread_attr_t thread_attr; argc = parse_options(argc, argv, options, bench_futex_requeue_usage, 0); if (argc) goto err; ncpus = sysconf(_SC_NPROCESSORS_ONLN); sigfillset(&act.sa_mask); act.sa_sigaction = toggle_done; sigaction(SIGINT, &act, NULL); if (!nthreads) nthreads = ncpus; else nthreads = futexbench_sanitize_numeric(nthreads); worker = calloc(nthreads, sizeof(*worker)); if (!worker) err(EXIT_FAILURE, "calloc"); if (!fshared) futex_flag = FUTEX_PRIVATE_FLAG; if (nrequeue > nthreads) nrequeue = nthreads; printf("Run summary [PID %d]: Requeuing %d threads (from [%s] %p to %p), " "%d at a time.\n\n", getpid(), nthreads, fshared ? "shared":"private", &futex1, &futex2, nrequeue); init_stats(&requeued_stats); init_stats(&requeuetime_stats); pthread_attr_init(&thread_attr); pthread_mutex_init(&thread_lock, NULL); pthread_cond_init(&thread_parent, NULL); pthread_cond_init(&thread_worker, NULL); for (j = 0; j < bench_repeat && !done; j++) { unsigned int nrequeued = 0; struct timeval start, end, runtime; /* create, launch & block all threads */ block_threads(worker, thread_attr); /* make sure all threads are already blocked */ pthread_mutex_lock(&thread_lock); while (threads_starting) pthread_cond_wait(&thread_parent, &thread_lock); pthread_cond_broadcast(&thread_worker); pthread_mutex_unlock(&thread_lock); usleep(100000); /* Ok, all threads are patiently blocked, start requeueing */ gettimeofday(&start, NULL); while (nrequeued < nthreads) { /* * Do not wakeup any tasks blocked on futex1, allowing * us to really measure futex_wait functionality. */ nrequeued += futex_cmp_requeue(&futex1, 0, &futex2, 0, nrequeue, futex_flag); } gettimeofday(&end, NULL); timersub(&end, &start, &runtime); update_stats(&requeued_stats, nrequeued); update_stats(&requeuetime_stats, runtime.tv_usec); if (!silent) { printf("[Run %d]: Requeued %d of %d threads in %.4f ms\n", j + 1, nrequeued, nthreads, runtime.tv_usec / (double)USEC_PER_MSEC); } /* everybody should be blocked on futex2, wake'em up */ nrequeued = futex_wake(&futex2, nrequeued, futex_flag); if (nthreads != nrequeued) warnx("couldn't wakeup all tasks (%d/%d)", nrequeued, nthreads); for (i = 0; i < nthreads; i++) { ret = pthread_join(worker[i], NULL); if (ret) err(EXIT_FAILURE, "pthread_join"); } } /* cleanup & report results */ pthread_cond_destroy(&thread_parent); pthread_cond_destroy(&thread_worker); pthread_mutex_destroy(&thread_lock); pthread_attr_destroy(&thread_attr); print_summary(); free(worker); return ret; err: usage_with_options(bench_futex_requeue_usage, options); exit(EXIT_FAILURE); } =71e0bbde0d88047f66b25721f69a441d46083748'>net: dsa: Add support for platform dataFlorian Fainelli1-0/+6 2017-02-07net: dsa: Rename and export dev_to_net_device()Florian Fainelli1-0/+1 2017-02-07net: phy: Add 2000base-x, 2500base-x and rxaui modesAndrew Lunn1-0/+9 2017-02-07virtio_net: refactor freeze/restore logic into virtnet reset logicJohn Fastabend1-0/+4 2017-02-06net: dsa: introduce bridge notifierVivien Didelot1-0/+10 2017-02-06net: dsa: add switch notifierVivien Didelot1-0/+7 2017-02-06net-next: treewide use is_vlan_dev() helper function.Parav Pandit1-4/+2 2017-02-06net: remove ndo_neigh_{construct, destroy} from stacked devicesIdo Schimmel1-4/+0 2017-02-06net/mlx5: TX WQE updateSaeed Mahameed2-3/+16 2017-02-06net/mlx5: Configure cache line size for start and end paddingDaniel Jurgens1-2/+4 2017-02-06can: rx-offload: Add support for timestamp based irq offloadingMarc Kleine-Budde1-1/+9 2017-02-06can: rx-offload: Add support for HW fifo based irq offloadingDavid Jander1-0/+51 2017-02-06net/mlx5: Fix static checker warningsOr Gerlitz1-1/+2 2017-02-05net: remove __napi_complete()Eric Dumazet1-1/+0 2017-02-04net: ipv6: Change notifications for multipath add to RTA_MULTIPATHDavid Ahern1-0/+1 2017-02-04net: ipv6: Allow shorthand delete of all nexthops in multipath routeDavid Ahern1-1/+3 2017-02-03net: remove support for per driver ndo_busy_poll()Eric Dumazet2-5/+0 2017-02-03Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-nextDavid S. Miller11-40/+60 2017-02-03sched: cls_flower: expose priority to offloading netdeviceJiri Pirko1-0/+1 2017-02-03lib: Introduce priority array area managerJiri Pirko1-0/+76 2017-02-03list: introduce list_for_each_entry_from_reverse helperJiri Pirko1-0/+13 2017-02-03trace: rename trace_print_hex_seq arg and add kdocDaniel Borkmann2-3/+3 2017-02-03bridge: uapi: add per vlan tunnel infoRoopa Prabhu3-0/+13 2017-02-03vxlan: support fdb and learning in COLLECT_METADATA modeRoopa Prabhu1-0/+1 2017-02-03ip_tunnels: new IP_TUNNEL_INFO_BRIDGE flag for ip_tunnel_info modeRoopa Prabhu1-0/+1 2017-02-03net/sched: act_ife: Change to use ife moduleYotam Gigi2-10/+1 2017-02-03net: Introduce ife encapsulation moduleYotam Gigi3-0/+70 2017-02-03net/sched: act_ife: Unexport ife_tlv_meta_encodeYotam Gigi1-2/+0 2017-02-03tcp: add tcp_mss_clamp() helperEric Dumazet1-0/+9 2017-02-02net: add LINUX_MIB_PFMEMALLOCDROP counterEric Dumazet1-0/+1 2017-02-02net: phy: marvell: Add support for 88e1545 PHYAndrew Lunn1-0/+1 2017-02-02unix: add ioctl to open a unix socket file with O_PATHAndrey Vagin1-0/+2 2017-02-02net: phy: Marvell: Add mv88e6390 internal PHYAndrew Lunn1-0/+6 2017-02-02Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/netDavid S. Miller9-30/+40 2017-02-02netfilter: allow logging from non-init namespacesMichal Kubeček1-0/+3 2017-02-02ipvs: free ip_vs_dest structs when refcnt=0David Windsor1-1/+1 2017-02-02netfilter: merge ctinfo into nfct pointer storage areaFlorian Westphal2-17/+15 2017-02-02netfilter: guarantee 8 byte minalign for template addressesFlorian Westphal1-0/+2 2017-02-02netfilter: add and use nf_ct_set helperFlorian Westphal2-2/+9 2017-02-02skbuff: add and use skb_nfct helperFlorian Westphal2-4/+11 2017-02-02netfilter: reduce direct skb->nfct usageFlorian Westphal1-3/+6 2017-02-02netfilter: conntrack: no need to pass ctinfo to error handlerFlorian Westphal1-1/+1