49bd97c28b
Use the dedicated non-atomic helpers for {clear,set}_bit() and their test variants, i.e. the double-underscore versions. Depsite being defined in atomic.h, and despite the kernel versions being atomic in the kernel, tools' {clear,set}_bit() helpers aren't actually atomic. Move to the double-underscore versions so that the versions that are expected to be atomic (for kernel developers) can be made atomic without affecting users that don't want atomic operations. No functional change intended. Signed-off-by: Sean Christopherson <seanjc@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: James Morse <james.morse@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Marc Zyngier <maz@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Oliver Upton <oliver.upton@linux.dev> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Sean Christopherson <seanjc@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Yury Norov <yury.norov@gmail.com> Cc: alexandru elisei <alexandru.elisei@arm.com> Cc: kvm@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu Cc: kvmarm@lists.linux.dev Cc: linux-arm-kernel@lists.infradead.org Link: http://lore.kernel.org/lkml/20221119013450.2643007-6-seanjc@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
56 lines
1.4 KiB
C
56 lines
1.4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/compiler.h>
|
|
#include <linux/bitmap.h>
|
|
#include <perf/cpumap.h>
|
|
#include <internal/cpumap.h>
|
|
#include "tests.h"
|
|
#include "debug.h"
|
|
|
|
#define NBITS 100
|
|
|
|
static unsigned long *get_bitmap(const char *str, int nbits)
|
|
{
|
|
struct perf_cpu_map *map = perf_cpu_map__new(str);
|
|
unsigned long *bm = NULL;
|
|
int i;
|
|
|
|
bm = bitmap_zalloc(nbits);
|
|
|
|
if (map && bm) {
|
|
for (i = 0; i < perf_cpu_map__nr(map); i++)
|
|
__set_bit(perf_cpu_map__cpu(map, i).cpu, bm);
|
|
}
|
|
|
|
if (map)
|
|
perf_cpu_map__put(map);
|
|
return bm;
|
|
}
|
|
|
|
static int test_bitmap(const char *str)
|
|
{
|
|
unsigned long *bm = get_bitmap(str, NBITS);
|
|
char buf[100];
|
|
int ret;
|
|
|
|
bitmap_scnprintf(bm, NBITS, buf, sizeof(buf));
|
|
pr_debug("bitmap: %s\n", buf);
|
|
|
|
ret = !strcmp(buf, str);
|
|
free(bm);
|
|
return ret;
|
|
}
|
|
|
|
static int test__bitmap_print(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,5"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3,5,7,9,11,13,15,17,19,21-40"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("2-5"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1-10,12-20,22-30,32-40"));
|
|
return 0;
|
|
}
|
|
|
|
DEFINE_SUITE("Print bitmap", bitmap_print);
|