drgn/libdrgn/openmp.h
Omar Sandoval f4af9b5b1d libdrgn: set default number of OpenMP threads without hyperthreads
In commit c4a122ead6 ("libdrgn: dwarf_info: scalably index all DIEs
per name"), I noted that indexing the Linux kernel was slower with 80
threads than with 8. After experimenting on multiple systems, I
determined that the slowdown was because of hyperthreading; limiting the
number of threads to the number of cores (not hyperthreads) was usually
faster, and never slower.

Unfortunately, OpenMP doesn't have a convenient way to express this, so
we have to parse sysfs and explicitly specify the number of threads
ourselves.

Compared to commit c4a122ead6 ("libdrgn: dwarf_info: scalably index
all DIEs per name"), this makes indexing the large C++ application half
a second faster, and the Linux kernel 70 ms faster, all while using less
resources.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-08-18 08:33:56 -07:00

21 lines
358 B
C

// Copyright (c) Meta Platforms, Inc. and affiliates.
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef DRGN_OPENMP_H
#define DRGN_OPENMP_H
#ifdef _OPENMP
#include <omp.h> // IWYU pragma: export
extern int drgn_num_threads;
#else
static inline int omp_get_thread_num(void)
{
return 0;
}
#define drgn_num_threads 1
#endif
#endif /* DRGN_OPENMP_H */